我有一个视图,想以标准方式呈现给用户(从屏幕底部向上滑动)。这个视图大约一半是透明背景,底部一半有一些输入字段(想象一下键盘弹出的方式)。当我在rootViewController上调用[self presentViewController]
时,它会向上滑动视图,但大约半秒钟后,原来透明的视图被黑色替换了。 无论是使用presentViewController还是presentModalViewController都会出现这种情况。如何更改这种行为?
iOS 8之前,你可以这样做:
[backgroundViewController setModalPresentationStyle:UIModalPresentationCurrentContext];
[backgroundViewController presentViewController:_myMoreAppsViewController animated:NO completion:nil];
backgroundViewController.providesPresentationContextTransitionStyle = YES;
backgroundController.definesPresentationContext = YES;
[overlayViewController setModalPresentationStyle:UIModalPresentationOverCurrentContext];
backgroundViewController.providesPresentationContextTransitionStyle = true
backgroundController.definesPresentationContext = true
overlayViewController.modalPresentationStyle = .OverCurrentContext
使用Xcode 6.3 beta 3和Swift 1.2在iOS 8.1上实现后,它可以完美地工作。
只是想评论一下,在找到并尝试Ray Wenderlich论坛的解决方案之前,我查看了三个不同的SO问题 - 最近的一个现在被标记为重复。
使用SWIFT 4,只需将此代码添加到您想要具有透明背景的视图控制器中即可。
override func viewDidLoad()
{
super.viewDidLoad()
self.modalPresentationStyle = .overFullScreen
self.view.backgroundColor = UIColor.clear
}
我曾经遇到过类似的问题,当使用控制器创建时,黑色背景会在短暂延迟后出现。
Disclaimer *vc = [[Disclaimer alloc]init];
Disclaimer *vc = (Disclaimer *)[self.storyboard instantiateViewControllerWithIdentifier:@"SBIDDisclaimer"];
[self presentViewController:vc animated:YES completion:nil];
我猜通过IB进行操作会进行一些额外的初始化。
modalPresentationStyle = .OverFullScreen
。使用.OverCurrentContext
会导致很多自动布局问题。 - Le Mot Juiced