美文网首页
iOS 下滑返回Dismiss

iOS 下滑返回Dismiss

作者: _Miyo | 来源:发表于2023-07-24 11:51 被阅读0次

    *我们在使用模态视图的时候 全屏显示下滑返回 不能同时兼得,这时需要我们处理滑动手势过程,引入 SwipeDismiss 可以最快速的实现这一需求,效果图如下(最下方附demo):

    87_1690191340.gif

    *使用 SwipeDismiss
    需要下滑返回的 ViewCointroller.m 遵循: UIViewControllerTransitioningDelegate

    #import "SwipeDismissController.h"
    
    #import "DismissAnimation.h"
    #import "PresentedAnimation.h"
    #import "SwipeUpInteractiveTransition.h"
    
    
    @interface SwipeDismissController ()<UIViewControllerTransitioningDelegate>
    @property (nonatomic, strong) SwipeUpInteractiveTransition *interactiveTransition;
    @end
    
    @implementation SwipeDismissController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        self.view.backgroundColor = [UIColor orangeColor];
        
        
        self.interactiveTransition = [[SwipeUpInteractiveTransition alloc]init:self];
        self.transitioningDelegate = self;
    }
    
    
    #pragma mark === UIViewControllerTransitioningDelegate ======
    -(id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {
        return [[PresentedAnimation alloc]init];
    }
    
    -(id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
        return [[DismissAnimation alloc]init];
    }
    
    -(id<UIViewControllerInteractiveTransitioning>)interactionControllerForDismissal:(id<UIViewControllerAnimatedTransitioning>)animator {
        return (self.interactiveTransition.isInteracting ? self.interactiveTransition : nil);
    }
    
    
    @end
    
    
    demo:https://github.com/Miyo518/SwipeDismiss

    相关文章

      网友评论

          本文标题:iOS 下滑返回Dismiss

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