Presenting modal in iOS 13 fullscreen

后端 未结 30 2173
囚心锁ツ
囚心锁ツ 2020-11-21 06:48

In iOS 13 there is a new behaviour for modal view controller when being presented.

Now it\'s not fullscreen by default and when I try to slide down, the app just dis

30条回答
  •  面向向阳花
    2020-11-21 07:15

    Here's my version of fix in ObjectiveC using Categories. With this approach you'll have default UIModalPresentationStyleFullScreen behaviour until another one explicitly set.

    #import "UIViewController+Presentation.h"
    #import "objc/runtime.h"
    
    @implementation UIViewController (Presentation)
    
    - (void)setModalPresentationStyle:(UIModalPresentationStyle)modalPresentationStyle {
        [self setPrivateModalPresentationStyle:modalPresentationStyle];
    }
    
    -(UIModalPresentationStyle)modalPresentationStyle {
        UIModalPresentationStyle style = [self privateModalPresentationStyle];
        if (style == NSNotFound) {
            return UIModalPresentationFullScreen;
        }
        return style;
    }
    
    - (void)setPrivateModalPresentationStyle:(UIModalPresentationStyle)modalPresentationStyle {
        NSNumber *styleNumber = [NSNumber numberWithInteger:modalPresentationStyle];
         objc_setAssociatedObject(self, @selector(privateModalPresentationStyle), styleNumber, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    }
    
    - (UIModalPresentationStyle)privateModalPresentationStyle {
        NSNumber *styleNumber = objc_getAssociatedObject(self, @selector(privateModalPresentationStyle));
        if (styleNumber == nil) {
            return NSNotFound;
        }
        return styleNumber.integerValue;
    }
    
    @end
    

提交回复
热议问题