如何通过 ios 中的 "over current context " 演示文稿以编程方式导航到另一个 viewcontroller,objective C

How to navigate programmatically to another viewcontroller with "over current context " presentation in ios 9, objective C

我正在使用 storyboard.so 构建我的应用程序 我可以在按下按钮时打开另一个视图控制器,通过 dragging.and 然后我可以 select presentation= over current context 对于 storyboard.But 中的 segue 我想要做的是 programmatically.I 找到了答案,但它说它只适用于 ipads.I 正在构建一个通用应用程序,所以我想要适用于所有设备。

在我的第一个视图控制器中

UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
UIViewController *middleViewController = [story instantiateViewControllerWithIdentifier:@"FlightMiddleViewController"];

在我的第二个视图控制器中,我放置了 viewDidLoad 方法

self.modalPresentationStyle = UIModalPresentationOverCurrentContext;

它适用于 while.that 意味着它透明一段时间然后屏幕 black.I 不知道为什么。

您需要在展示前设置关注属性。

self.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext

同时将父控制器的 definesPresentationContext 属性 设置为 true

是的,它仅适用于 iPad,因为模态呈现和弹出控制器仅在 iPad 中受支持。

实际上,在 iPhone 上实现 OverCurrentContext 演示风格并不难。看看UIViewController custom transition,它在iOS 7中介绍过。你会知道如何去做。

它适用于 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];

}

这也适用于 iphones。

For anyone that was doning performSegue(.. programmatically

在我的例子中,我有一个 modal 呈现 button。点击按钮应该会按下一个新的 viewController,但它会被推入 fullScreen,即使我在 modal

中也是如此

所以经过一点搜索,我发现我在 xcode 中设置了 storyBoardPresentation => fullScreen。所以我不得不改变是 Current Context