Dismiss modal view form sheet controller on outside tap

前端 未结 13 1061
猫巷女王i
猫巷女王i 2020-12-01 06:16

I am presenting a modal view controller as a form sheet and dismissing it when the cancel button, which is a bar button item, is clicked. I need to dismiss it when I tap on

13条回答
  •  被撕碎了的回忆
    2020-12-01 07:09

    I made a navigationController that auto dismiss for iPad

    https://github.com/curciosobrinho/NavAutoDismiss

    It is just the same code as above, working on iOS 8.

    So, all the credits go to the people above.

    I just did it to be more generic and easier to use.

    You just need to copy BOTH files to your project

    Import the header file (.h)

    And use your viewcontroller (that you want to show) as the rootViewController.

    How to use it:

    //Import the .h file
    #import "NavDismissViewController.h"
    
    //Instanciate your view controller (the view you want to present)
    
    YourViewController * yourVC = [YourViewController new];
    
    //Instanciate the NavDismissViewController with your view controller as the rootViewController
    
    NavDismissViewController *nav = [[NavDismissViewController alloc] initWithRootViewController:yourVC];
    
    //if you want to change the navigationBar translucent behaviour
    
    [nav.navigationBar setTranslucent:NO];
    
    //Choose the Modal style
    
    nav.modalPresentationStyle=UIModalPresentationFormSheet;
    
    //present your controller
    
    [self presentViewController:nav animated:YES completion:nil];
    
    //Done
    

提交回复
热议问题