In iOS, how to drag down to dismiss a modal?

后端 未结 15 2239
粉色の甜心
粉色の甜心 2020-11-28 00:41

A common way to dismiss a modal is to swipe down - How do we allows the user to drag the modal down, if it\'s far enough, the modal\'s dismissed, otherwise it animates back

相关标签:
15条回答
  • 2020-11-28 01:07

    created a demo for interactively dragging down to dismiss view controller like snapchat's discover mode. Check this github for sample project.

    0 讨论(0)
  • 2020-11-28 01:07

    In Objective C : Here's the code

    inviewDidLoad

    UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc]
                                                 initWithTarget:self action:@selector(swipeDown:)];
    swipeRecognizer.direction = UISwipeGestureRecognizerDirectionDown;
    [self.view addGestureRecognizer:swipeRecognizer];
    
    //Swipe Down Method
    
    - (void)swipeDown:(UIGestureRecognizer *)sender{
    [self dismissViewControllerAnimated:YES completion:nil];
    }
    
    0 讨论(0)
  • 2020-11-28 01:09

    I've created an easy to use extension.

    Just inherent Your UIViewController with InteractiveViewController and you are done InteractiveViewController

    call method showInteractive() from your controller to show as Interactive.

    0 讨论(0)
提交回复
热议问题