我正在使用Storyboard构建应用程序。因此,在拖动按钮时可以打开另一个视图控制器,方法是拖动,然后在Storyboard中为segue选择presentation
= over current context
。但是我想要以编程方式进行操作。我找到了答案,但它说它仅适用于ipad。我正在构建一个通用应用,因此我想在所有设备上使用。
在我的第一个视图控制器中
UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
UIViewController *middleViewController = [story instantiateViewControllerWithIdentifier:@"FlightMiddleViewController"];
在第二个视图控制器中,我放入了viewDidLoad方法
self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
它会工作一段时间,这意味着它会透明一段时间然后黑屏。我不知道为什么会这样。
它也适用于iPhone,并且与ios 9> =
这就是你想要做的。
在您的第一个视图控制器中,在设置应显示哪个视图之前,
- (IBAction)searchNowAction:(id)sender {
UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
UIViewController *secondViewController = [story instantiateViewControllerWithIdentifier:@"secondviewControllerSBname"];
secondViewController.modalPresentationStyle = UIModalPresentationOverFullScreen;
secondViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:secondViewController animated:YES completion:nil];
}
这也适用于iPhone。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句