UIViewController中,我有一个UIScrollView占据了一半的屏幕。此UIScrollView包含UIView的集合。在某些特定事件(例如,滑动)上,我希望我的UIScrollView动画全屏显示,如何实现此行为?

最佳答案

尝试这个...

// 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;
}
}

10-08 06:58
查看更多