将 UIViewController 呈现为具有透明背景的模态 [英] Present UIViewController as a modal with transparent background

查看:60
本文介绍了将 UIViewController 呈现为具有透明背景的模态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 iOS 7 和 iOS 8 上呈现一个具有透明背景的视图控制器.只需将视图控制器的 modalPresentationStyle 属性更改为 FormSheet,我就可以让它在 iOS 7.1 上运行.

I'm trying to present a viewcontroller with a transparent background on both iOS 7 and iOS 8. Just by changing the viewcontroller's modalPresentationStyle property to FormSheet I can get it working on iOS 7.1.

我想要的是在 ios7+ 上通用的方式

What I want is a universal way to that on ios7+

我尝试使用其他选项来设置 modalPresentationStyle,例如:OverCurrentContext、CurrentContext 和 PageSheet.

I have tried using other options to modalPresentationStyle, like: OverCurrentContext, CurrentContext and PageSheet.

我也尝试使用 modalPresentationStyle.Custom 但没有成功.

I also tried to use the modalPresentationStyle.Custom but didnt have any success.

如果有任何帮助,我有 NavigationController.

I have NavigationController if that helps in anything.

呈现视图控制器的代码:

The code for the presenting view controller:

InfoViewController *info = [[InfoViewController alloc] initWithNibName:@"InfoViewController" bundle:nil];
[self presentViewController:info animated:YES completion:nil];

以及所呈现的 ViewController 的 viewDidLoad(我认为在这方面有相关部分)的代码:

And the code for the viewDidLoad(which I think has a relevant part on this) of the presented ViewController:

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
    self.modalPresentationStyle = UIModalPresentationStyle.PageSheet
}

我使用的是 swift 和 Xcode 6.这是我现在拥有的和我想要的分别的屏幕截图:

I´m using swift and Xcode 6. Here´s a screenshot of what I have now and of what I want, respectively:

这是一个示例代码:https://github.com/pbassut/TransBackgroundViewController

推荐答案

对于那些在呈现 UIViewController 之前仍然有这个问题的人,将呈现的 UIViewController 的 modalPresentationStyle 设置为 .Custom 并且它将在 iOS 8(Xcode 6.1) 上工作.也就是说,你应该在呈现的 UIViewController 中设置它

For those still with this problem before presenting the UIViewController set the modalPresentationStyle of the presented UIViewController to .Custom and it will work on iOS 8(Xcode 6.1). That is, you should set it in the presenting UIViewController

这篇关于将 UIViewController 呈现为具有透明背景的模态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆