首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >presentViewController侧面动画

presentViewController侧面动画
EN

Stack Overflow用户
提问于 2013-02-24 13:42:22
回答 2查看 13K关注 0票数 8

我有一个单一的视图应用程序,并希望显示一个新的ViewController时,按下导航栏按钮在右手边。我用这个代码来命名这个VC:

代码语言:javascript
复制
- (IBAction)createEntryButton:(id)sender {
    CreateEntryViewController *vc2 = [[CreateEntryViewController alloc] init];
    [self presentViewController:vc2 animated:TRUE completion:nil];
}

然而,这个动画从底部引入了vc2,根据我的UI,这似乎违反了直觉。所以我的问题是:

如何使我的vc2从右边而不是底部与presentViewController?一起出现

谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-02-24 14:10:17

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

如果您已经在NavigationController中

代码语言:javascript
复制
[self.navigationCtroller pushViewController:vc2 animated:TRUE completion:nil]

如果不是,请修改将视图控制器添加到窗口的代码。如果您的VC是rootWindowController,并且您没有使用故事板,这很可能在您的AppDelegate中。

如果您使用故事板,请调整故事板,以便您在导航控制器内。

否则,如果您出于任何原因不想这样做::)只需在2.VC的视图中使用UIView动画:vc2.view手动动画.

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

代码语言:javascript
复制
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];
}];

在完成块中,视图控制器vc2呈现为非动画的,就像您自己已经做的那样。

票数 9
EN

Stack Overflow用户

发布于 2016-09-29 14:05:48

这个帮了我,

代码语言:javascript
复制
- (void)presentNewViewController{
    NewViewController *objNewViewController =[[NewViewController alloc]initWithNibName:@"NewViewController" bundle:nil];

    UIView *tempNewVCView = [UIView new];
    tempNewVCView = objNewViewController.view;
    tempNewVCView.frame = self.view.frame;

    CGRect initialFrame = self.view.frame;
    initialFrame.origin.x = self.view.frame.size.width;

    tempNewVCView.frame = initialFrame;

    [self.view addSubview:tempNewVCView];

    [UIView animateWithDuration:0.3 animations:^{
        tempNewVCView.frame = self.view.frame;
    } completion:^(BOOL finished) {
        [self presentViewController:objNewViewController animated:NO completion:^{
        }];
    }];
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15052308

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档