是否可以在iPad上呈现模态视图控制器而不调暗背景?

问题描述 投票:0回答:4

我想展示一个模态视图控制器,它不会使其后面的内容变暗。只需使用标准的presentViewController。仅将视图控制器的子视图添加到父视图会导致问题。

ios ipad cocoa-touch
4个回答
1
投票

试试这个:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    // remove the dimming view if needed, when this view controller will appear as modal
    id <UIViewControllerTransitionCoordinator> transitionCoordinator = self.transitionCoordinator;
    if (transitionCoordinator.presentationStyle != UIModalPresentationNone) {
        for (UIView *transitionContainerSubview in transitionCoordinator.containerView.subviews) {
            if ([NSStringFromClass([transitionContainerSubview class]) isEqualToString:@"UIDimmingView"]) {
                transitionContainerSubview.hidden = YES;
            }
        }
    }
}

0
投票

也许看看

UIModalPresentationStyle

typedef NS_ENUM(NSInteger, UIModalPresentationStyle) {
UIModalPresentationFullScreen = 0,
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2
UIModalPresentationPageSheet,
UIModalPresentationFormSheet,
UIModalPresentationCurrentContext,
#endif
};

在调用

setModalPresentationStyle:
之前,您可以在视图控制器上使用
presentViewController:animated:completion:
指定模式呈现的类型。


0
投票

最好的办法是将视图添加为子视图而不是模态视图控制器。我不知道你的具体用途,但从它的声音来看,无论如何逻辑应该在同一个控制器中。

myControllerThatWasModal.view.layer.opacity = 0.0f;
myControllerThatWasModal.view.hidden = YES;
[self.view addSubview:myControllerThatWasModal.view];
[UIView animateWithDuration:1.0 animations:^{
     myControllerThatWasModal.view.layer.opacity = 1.0f;   
}];

这是根据记忆编写的,因此请原谅任何错误,而且为了使其工作,您需要在它将覆盖的视图控制器中拥有“模态”视图控制器的实例。


0
投票

使用 iOS 15 或更高版本时,您可以使用它来防止模态视图控制器变暗:

modalController.sheetPresentationController?.largestUndimmedDetentIdentifier = .large

在调用

present
方法之前设置此属性。

© www.soinside.com 2019 - 2024. All rights reserved.