2016-03-10 18 views
1

我有一個視圖,我想顯示一個自定義大小的UIViewController。但我沒有成功。這是我的代碼。Swift - iOS 9:我如何在iOS 9中使用自定義大小來呈現UIViewController?

var vx = KeyboardViewController() 
vx.modalPresentationStyle = UIModalPresentationStyle.FormSheet 
vx.preferredContentSize = CGSizeMake(self.view.frame.width, 150)  
self.presentViewController(vx, animated: true, completion: nil) 

這UIViewController中顯示在全屏幕尺寸

回答

5

你需要給所呈現的視圖控制器的自定義transitioningDelegate,然後就可以插入自定義UIPresentationController到演示的過程,其frameOfPresentedViewInContainerView你將適當覆蓋。

+0

在這裏可以下載的工程示例項目:https://github.com/mattneub/custom-alert-view-iOS7 – matt

+0

我不理解代碼,這對我來說太複雜了。我見過這個答案,但沒有工作:http://stackoverflow.com/questions/29219688/present-modal-view-controller-in-half-size-parent-controller。有沒有更簡單的方式來呈現半尺寸uiviewcontroller? – TomSawyer

+3

這個答案和我告訴你的告訴你完全一樣,並告訴你如何去做。 – matt