iOS 下滑返回Dismiss

2023-07-24  本文已影响0人  _Miyo

*我们在使用模态视图的时候 全屏显示下滑返回 不能同时兼得,这时需要我们处理滑动手势过程,引入 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
上一篇下一篇

猜你喜欢

热点阅读