我有ViewController
,當用戶點擊它的底部時,其他ViewController
使用segue Present Modally
彈出。 是否可以給他們自定義大小?我嘗試通過Use Preferred Explicit Size
選項給內容大小,但它沒有幫助。我希望這個VC能夠彈出並從當前的VC中拿走70%的VC。如何設置自定義大小以呈現Modally ViewController
1
A
回答
0
使用UIContainerView
代替 「現模態」 SEGUE解決它。
這是我如何做,以防其他人正在努力解決同樣的問題。
請勿設置任何分段/嵌入到VC B/W UIContainerView
。添加STORYBOARD ID。
@IBOutlet weak var containerView: UIView!
weak var currentViewController: UIViewController?
override func viewDidLoad() {
self.currentViewController = self.storyboard?.instantiateViewController(withIdentifier: "ContainerVC")
self.currentViewController!.view.translatesAutoresizingMaskIntoConstraints = false
self.addChildViewController(self.currentViewController!)
self.addSubview(subView: self.currentViewController!.view, toView: self.containerView)
super.viewDidLoad()
}
//MARK:- CONTAINER VIEW
func addSubview(subView:UIView, toView parentView:UIView) {
parentView.addSubview(subView)
var viewBindingsDict = [String: AnyObject]()
viewBindingsDict["subView"] = subView
parentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[subView]|",
options: [], metrics: nil, views: viewBindingsDict))
parentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[subView]|",
options: [], metrics: nil, views: viewBindingsDict))
}
func cycleFromViewController(oldViewController: UIViewController, toViewController newViewController: UIViewController) {
oldViewController.willMove(toParentViewController: nil)
self.addChildViewController(newViewController)
self.addSubview(subView: newViewController.view, toView:self.containerView!)
newViewController.view.alpha = 0
newViewController.view.layoutIfNeeded()
UIView.animate(withDuration: 0.5, animations: {
newViewController.view.alpha = 1
oldViewController.view.alpha = 0
},
completion: { finished in
oldViewController.view.removeFromSuperview()
oldViewController.removeFromParentViewController()
newViewController.didMove(toParentViewController: self)
})
}
然後,每當你想改變VIEW據Action
let newViewController : DestinationVC = self.storyboard?.instantiateViewController(withIdentifier: "DestinationVC") as! DestinationVC
newViewController.data = dataToBeSentViaSegue // Passing DATA
newViewController.view.translatesAutoresizingMaskIntoConstraints = false
self.cycleFromViewController(oldViewController: self.currentViewController!, toViewController: newViewController)
self.currentViewController = newViewController
2
看看這個,讓我知道你是否想要任何澄清。
__weak IBOutlet UIView *conViewers;
- (void)callingOfCustomView:(UIViewController *)showPushedVC
{
[showPushedVC.view setTranslatesAutoresizingMaskIntoConstraints:YES];
showPushedVC.view.frame = conViewers.bounds;
//**>> Add child view into container view
[conViewers addSubview: showPushedVC.view];
[self addChildViewController: showPushedVC];
[showPushedVC didMoveToParentViewController:self];
}
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
ViewersVC *objViewers = [storyboard instantiateViewControllerWithIdentifier:@"ViewersVC"];
[self callingOfCustomView:objViewers];
將在swift中進行更新。
0
你應該在你的第二個VC
(我的意思是,你正在演示),並設置背景是VC's view
爲clear color
添加顏色的大小70%的視圖,以便爲剩餘的30%將顯示以前的VC。
例如你的VC的高度,然後100像素與70 pixel
高度再添view
,並設置clear background color
到self.view
我的意思是VC的主要觀點!
現在設置modalPresentationStyle
到您的VC提出它像以前一樣,
yourVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:yourVC animated:YES completion:^{
}];
如果你給的支持不是ios 8
較小,那麼你需要設置setModalPresentationStyle
到NavigationController(If you are using else parent view controller - which are presenting view controller)
一樣,
[self.navigationController setModalPresentationStyle:UIModalPresentationCurrentContext];
[self presentViewController:yourVC animated:YES completion:^{
}];
斯威夫特:
yourVC.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext
self.presentViewController(yourVC, animated: true) {
}
或
self.navigationController?.modalPresentationStyle = UIModalPresentationStyle.CurrentContext
self.presentViewController(yourVC, animated: true) {
}
相關問題
- 1. 使用自定義動畫呈現ViewController
- 2. 問題與呈現自定義大小ViewController模式在ios 8與鍵盤
- 3. 如何在頁面呈現之前設置自定義文化?
- 4. 設置NSTextField的自定義大小
- 5. 自定義字體大小設置
- 6. 如何設置自定義UIView的大小/位置以將其放置在自定義UITableViewCell中?
- 7. 用導航呈現自定義大小的視圖控制器
- 8. 如何在summernote中設置自定義字體大小列表?
- 9. 如何在擺動中設置光標的自定義大小?
- 10. 如何設置jquery ui的自定義調整大小手柄?
- 11. 如何設置自定義按鈕的大小?
- 12. 如何設置自定義表面視圖的大小
- 13. 是否可以爲NSString設置自定義字體和大小?
- 14. 如何在呈現爲presentModalViewController之前設置ViewController的屬性?
- 15. Magento設置自定義模板來呈現窗口小部件實例
- 16. Grails - 自定義Flash.message呈現
- 17. ASP.NET MVC:設置自定義名稱來呈現的HTML元素
- 18. JSF2將UISelectItem設置爲不呈現。使用自定義MenuRenderer
- 19. 如何使自定義CSS字體呈現完全像設計
- 20. 如何設置使用自定義表單字段類型呈現的模板?
- 21. 從appDelegate呈現ViewController
- 22. 何時呈現自定義WPF TextBlock?
- 23. 如何設置自舉下拉大小?
- 24. UIScrollView自定義ViewController
- 25. presentModalViewController - ViewController自動消失後呈現
- 26. 如何自定義UAModalPanel的大小?
- 27. 如何自定義模態的大小
- 28. 如何自定義JCoverFlip的大小?
- 29. 從模態呈現的ViewController呈現ViewController時發生崩潰
- 30. 設置窗口大小後,SDL未呈現到完整窗口
你在iPhone或iPad上嘗試? –
僅限iPhone。 – Nitesh
你可以看看這個http://stackoverflow.com/questions/25811199/ios-8-change-the-size-of-presented-modal-view-controller –