且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在iOS中使用滑动手势进行页面卷曲?

更新时间:2023-02-26 21:40:07

使用UISwipeGestureRecognizer和UIViewAnimationTransition

Use the UISwipeGestureRecognizer and UIViewAnimationTransition

- (void)handleSwipe:(UISwipeGestureRecognizer *)sender {

    if(sender.state == UIGestureRecognizerStateEnded) {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.3];
        [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:window cache:YES];

        [self.view addSubview:[newView view]];
        [oldView removeFromSuperview];

        [UIView commitAnimations];
    }                  
}
- (void)createGestureRecognizers:(UIView *) target {
    UISwipeGestureRecognizer *rightSwipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];

    [rightSwipeRecognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
    [target addGestureRecognizer:rightSwipeRecognizer];
    [rightSwipeRecognizer release];
}