我希望以标准方式向用户呈现(从屏幕底部向上滑动).大约一半的视图是透明背景,下半部分有一些输入字段(想象键盘弹出的方式).当我调用[self presentViewController]rootViewController时,它会向上滑动视图,但是大约半秒后,视图过去是透明的,而是用黑色代替.这与presentViewController和presentModalViewController都会发生.如何改变这种行为?
Max*_*eod 22
这是可能的,rockybalboa在raywenderlich.com上的论坛帖子中提供了解决此问题的方法:
iOS 8 UIModalPresentationCurrentContext不透明?
该解决方案在Objective-C中引用巴尔博亚的答案:
在iOS 8之前,您执行此操作:
[backgroundViewController setModalPresentationStyle:UIModalPresentationCurrentContext];
[backgroundViewController presentViewController:_myMoreAppsViewController animated:NO completion:nil];
Run Code Online (Sandbox Code Playgroud)
在iOS 8中,您必须这样做:
backgroundViewController.providesPresentationContextTransitionStyle = YES;
backgroundController.definesPresentationContext = YES;
[overlayViewController setModalPresentationStyle:UIModalPresentationOverCurrentContext];
Run Code Online (Sandbox Code Playgroud)
用Swift等价物补充上面的代码:
backgroundViewController.providesPresentationContextTransitionStyle = true
backgroundController.definesPresentationContext = true
overlayViewController.modalPresentationStyle = .OverCurrentContext
Run Code Online (Sandbox Code Playgroud)
在iOS 8.1和Swift 1.2上使用Xcode 6.3 beta 3实现了这一点,它完美地运行.
只是评论我在查找和尝试Ray Wenderlich论坛解决方案之前,已经查看了三个不同的SO问题 - 现在标记为重复.
最后,看起来它不可能是透明的,我通过将此视图添加为根视图控制器边界之外的子视图来解决这个问题,然后使用动画块将其滑入到位。不需要太多额外的代码,但如果能够使用标准的 iOS 行为来完成它就太好了。
| 归档时间: |
|
| 查看次数: |
7610 次 |
| 最近记录: |