Ios 长按手势调整UIScrollView的大小
我在使用故事板的UITableViewController的顶部(导航栏正下方)有一个UIScrollView。UIScrollView的默认大小为320x50。当用户按住scrollView至少1秒时,我希望UIScrollView的大小增加一倍(320x100),以便通过动画显示更多细节。如果可能的话,右下方的UITableView应使用它设置动画,并向下移动50 当UIScrollView处于较大设置时,按住它至少1秒将产生相反的动画,并且UIScrollView将动画恢复到其原始大小 我该怎么做?提前谢谢你!以下是我目前掌握的情况:Ios 长按手势调整UIScrollView的大小,ios,xcode,uiscrollview,resize,uigesturerecognizer,Ios,Xcode,Uiscrollview,Resize,Uigesturerecognizer,我在使用故事板的UITableViewController的顶部(导航栏正下方)有一个UIScrollView。UIScrollView的默认大小为320x50。当用户按住scrollView至少1秒时,我希望UIScrollView的大小增加一倍(320x100),以便通过动画显示更多细节。如果可能的话,右下方的UITableView应使用它设置动画,并向下移动50 当UIScrollView处于较大设置时,按住它至少1秒将产生相反的动画,并且UIScrollView将动画恢复到其原始大小 我
- (void)viewDidLoad {
[super viewDidLoad];
self.featureScrollExpanded = NO;
UILongPressGestureRecognizer* featureHold = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector (longHold:)];
[featureHold setDelaysTouchesBegan : YES];
featureHold.minimumPressDuration = 0.6;
featureHold.numberOfTouchesRequired = 1;
[self.featureScrollView addGestureRecognizer:featureHold];
[featureHold release];
}
- (void)longHold:(UIGestureRecognizer*)sender {
if (self.featureScrollExpanded==NO) {
self.featureScrollExpanded=YES;
//make it bigger
}
else {
self.featureScrollExpanded=NO;
//make it smaller
}
}
制作动画:
CGRect frame = yourScrollView.frame;
frame.size.height += 50;
[UIView animateWithDuration:0.6
animations:^{
yourScrollView.frame = frame;
} completion:^(BOOL finished) {
//do your other animation here if you want to
//or do them both together and lose this block
}
];
或者,如果您需要更多的概述:
CGRect frame = yourScrollView.frame;
frame.size.height += 50;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.6];
[self.yourScrollView setFrame:frame];
[UIView commitAnimations];
为了用动画调整“self.featureScrollView”的大小,我应该把什么放在上面写着“//使它变大”和“//使它变小”的地方?我只是不知道该怎么做。事实上,等一下,每当我尝试使用
frame.size.height-=50使它变小时代码>滚动视图刚刚消失。不过,让它变得更大是完美的。