美文网首页
iOS交互式动画转场

iOS交互式动画转场

作者: Maggie的小蜗居 | 来源:发表于2016-08-21 21:31 被阅读591次

    iOS交互式动画转场

    实现UIPercentDrivenInteractiveTransition

    -(void)updateInteractiveTransition:(CGFloat)percentComplete 更新百分比,一般通过手势识别的长度之类的来计算一个值,然后进行更新。

    -(void)cancelInteractiveTransition 取消操作,返回切换前的状态
    –(void)finishInteractiveTransition 完成操作,更新到切换后的状态

    当手势结束,根据手势的状态判断是取消还是完成,调用如下方法
    finishInteractiveTransition 或者 cancelInteractiveTransition 方法.

    
    - (void)handlePopRecognizer:(UIScreenEdgePanGestureRecognizer*)recognizer {
        // 计算滑了多远
        CGFloat progress = [recognizer translationInView:self.view].x / (self.view.bounds.size.width * 1.0);
        progress = MIN(1.0, MAX(0.0, progress));
    
        if (recognizer.state == UIGestureRecognizerStateBegan) {
            // 创建过渡对象,弹出viewController
            self.interactivePopTransition = [[UIPercentDrivenInteractiveTransition alloc] init];
            [self.navigationController popViewControllerAnimated:YES];
        }
        else if (recognizer.state == UIGestureRecognizerStateChanged) {
            // 更新 interactive transition 的进度
            [self.interactivePopTransition updateInteractiveTransition:progress];
        }
        else if (recognizer.state == UIGestureRecognizerStateEnded || recognizer.state == UIGestureRecognizerStateCancelled) {
            // 完成或者取消过渡
            if (progress > 0.5) {
                [self.interactivePopTransition finishInteractiveTransition];
            }
            else {
                [self.interactivePopTransition cancelInteractiveTransition];
            }
    
            self.interactivePopTransition = nil;
        }
    
    }
    
    

    相关文章

      网友评论

          本文标题:iOS交互式动画转场

          本文链接:https://www.haomeiwen.com/subject/lhswsttx.html