来自侧面的presentViewController动画

cas*_*sen 8 viewcontroller ios

我有一个单独的视图应用程序,并希望在按右侧的导航栏按钮时显示一个新的ViewController.我通过以下代码调用此VC:

- (IBAction)createEntryButton:(id)sender {
    CreateEntryViewController *vc2 = [[CreateEntryViewController alloc] init];
    [self presentViewController:vc2 animated:TRUE completion:nil];
}
Run Code Online (Sandbox Code Playgroud)

然而,这个动画vc2从底部带来了根据我的UI看起来反直觉的内容.所以我的问题是:

如何使用presentViewController从右侧而不是底部显示我的vc2?

谢谢.

Dai*_*jan 9

最干净的是使用navigationController来推送和弹出视图.

如果您已经在NavigationController中

[self.navigationCtroller pushViewController:vc2 animated:TRUE completion:nil]
Run Code Online (Sandbox Code Playgroud)

如果不是,请调整视图控制器添加到窗口的代码.如果您的VC是rootWindowController并且您没有使用故事板,那么这可能在您的AppDelegate中

如果您使用故事板,请调整故事板,以便您进入导航控制器


ELSE,如果您因任何原因不想这样::)只需使用[UIView animate:vc2.view ....]在2. VC的视图中手动设置动画.

内联编写 - 方法名称不匹配但显示一般方法:

UIView *v = vc2.view;
CGRect f = v.frame;
f.origin.x += self.view.frame.size.width; //move to right

v.frame = f;

[UIView animateWithDuration:0.5 animations:^{
    v.frame = self.view.frame;
} completion:^(BOOL finished) {
   [self presentViewController:vc2 animated:NO completion:nil];
}];
Run Code Online (Sandbox Code Playgroud)

在完成块中,视图控制器vc2是非动画的,就像你自己已经做过的那样