我有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. 自定义字体大小设置
- 5. 设置NSTextField的自定义大小
- 6. 如何设置自定义UIView的大小/位置以将其放置在自定义UITableViewCell中?
- 7. 用导航呈现自定义大小的视图控制器
- 8. 如何在jsf中设置对话框的自定义大小?
- 9. 如何设置jquery ui的自定义调整大小手柄?
- 10. 如何在摆动中设置光标的自定义大小?
- 11. 如何设置自定义表面视图的大小
- 12. 如何设置自定义按钮的大小?
- 13. 如何设置自定义对象的矢量大小?
- 14. 如何在summernote中设置自定义字体大小列表?
- 15. Fabric.js:如何将自定义大小设置为文本或IText?
- 16. 是否可以为NSString设置自定义字体和大小?
- 17. 如何在呈现为presentModalViewController之前设置ViewController的属性?
- 18. 如何呈现viewController,而我仍然可以看到背景viewController
- 19. 如何呈现自定义小枝函数内的内容?
- 20. Magento设置自定义模板来呈现窗口小部件实例
- 21. WPF和自定义呈现
- 22. Grails - 自定义Flash.message呈现
- 23. ASP.NET MVC:设置自定义名称来呈现的HTML元素
- 24. JSF2将UISelectItem设置为不呈现。使用自定义MenuRenderer
- 25. 如何使自定义CSS字体呈现完全像设计
- 26. 如何将自定义搜索栏的ProgressDrawable大小设置为小于ProgressBackground
- 27. 如何设置使用自定义表单字段类型呈现的模板?
- 28. 如何通过presentModalViewController呈现任何viewcontroller?
- 29. 从appDelegate呈现ViewController
- 30. 如何设置自举下拉大小?
你在iPhone或iPad上尝试? –
仅限iPhone。 – Nitesh
你可以看看这个http://stackoverflow.com/questions/25811199/ios-8-change-the-size-of-presented-modal-view-controller –