[英]Resize UIScrollView on Long Press Gesture
我在使用Storyboard的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];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.