Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

swift - Present UIViewController as a modal with transparent background

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.

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

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

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

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];

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
}

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

enter image description hereenter image description here

Here's an example code: https://github.com/pbassut/TransBackgroundViewController

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...