在UIViewController
中,我有UIScrollView
占据了屏幕的一半。此UIScrollView
包含UIView
的集合。在某些特定事件(例如滑动)上,我希望UIScrollView
能够全屏显示全屏,我该如何实现此行为?
答案 0 :(得分:1)
试试这个......
// adding swipe gesture to your scrollview
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
// Set swipe direction.
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[scrollview addGestureRecognizer:swipeLeft];
// add gesture action method
- (void)handleSwipe:(UISwipeGestureRecognizer *)swipe {
// if you are having only one swipe gesture, you no need to add the below condition. you can add the code inside the condition
if (swipe.direction == UISwipeGestureRecognizerDirectionLeft) {
NSLog(@"Left Swipe");
scrollView.contentSize = self.view.frame;
scrollView.frame = self.view.frame;
}
}
答案 1 :(得分:0)
尝试在事件上使用此方法并设置:
scrollView.contentSize = CGSizeMake(847, 800); // change on basis of your requirement
为动画滚动视图:
- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated; // animate at constant velocity to new offset
答案 2 :(得分:0)
引用@ RAJA的回答并稍作改进:
[UIView beginAnimations:@"whatever" context:nil];
scrollView.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height * <count of subviews>);
scrollView.frame = self.view.frame;
[UIView commitAnimations];
答案 3 :(得分:0)
我只是扩展第一个答案,如果你想为上面的过程设置动画,可以通过附加以下代码来实现:
- (void)handleSwipe:(UISwipeGestureRecognizer *)swipe
{
if (swipe.direction == UISwipeGestureRecognizerDirectionLeft)
{
[UIView animateWithDuration:0.15f // set duration for your animation here
animations:^{
scrollView.contentSize = self.view.frame;
scrollView.frame = self.view.frame;
}
completion:^(BOOL finished){
NSLog(@"completion block");
}];
}
}