我有一个单一的视图应用程序,并希望显示一个新的ViewController时,按下导航栏按钮在右手边。我用这个代码来命名这个VC:
- (IBAction)createEntryButton:(id)sender {
CreateEntryViewController *vc2 = [[CreateEntryViewController alloc] init];
[self presentViewController:vc2 animated:TRUE completion:nil];
}然而,这个动画从底部引入了vc2,根据我的UI,这似乎违反了直觉。所以我的问题是:
如何使我的vc2从右边而不是底部与presentViewController?一起出现
谢谢。
发布于 2013-02-24 14:10:17
最干净的方法是使用navigationController来推送和弹出视图。
如果您已经在NavigationController中
[self.navigationCtroller pushViewController:vc2 animated:TRUE completion:nil]如果不是,请修改将视图控制器添加到窗口的代码。如果您的VC是rootWindowController,并且您没有使用故事板,这很可能在您的AppDelegate中。
如果您使用故事板,请调整故事板,以便您在导航控制器内。
否则,如果您出于任何原因不想这样做::)只需在2.VC的视图中使用UIView动画:vc2.view手动动画.
编写的内联方法名称不匹配,但显示了一般方法:
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呈现为非动画的,就像您自己已经做的那样。
发布于 2016-09-29 14:05:48
这个帮了我,
- (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:^{
}];
}];
}https://stackoverflow.com/questions/15052308
复制相似问题