我的应用程序是使用UINavigationController为所有导航设置的。我想使用模态转换在应用程序中呈现特定的视图控制器。问题是我希望将新VC嵌入导航控制器中,但只有一个视图需要使用模态动画而不是推动。
如何在UINavigationController中的单个视图控制器上实现此模态动画/转换?
请记住,在此模式动画发生后,该页面上的按钮将继续按照标准UINavigationController推送动画工作。
答案 0 :(得分:4)
ITviewViewController *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"vc"];
vc.modalPresentationStyle = UIModalPresentationFullScreen;
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:Nil];
用视图控制器名称替换伪代码。
答案 1 :(得分:2)
使用iOS7,可以使用新的自定义转换API。您可以在此处找到更多信息:http://www.objc.io/issue-5/view-controller-transitions.html
您可以创建动画控制器(交互式或其他),并使用导航栏代理的相应方法传递它。在动画控制器中,使用UIView
动画API执行自定义动画。在您的情况下,动画应该从底部到前进动画执行幻灯片,并从一个地方滑到另一个底部以进行反向动画。如果您支持交互式动画,您甚至可以控制动画相对于手指幻灯片的曲线。
答案 2 :(得分:1)
默认情况下,模态视图为全屏。您需要更改演示文稿样式以显示navigationBar
编辑:这仅适用于iPad。对于iPhone,您可以使用MZformsheet或Kentnguyen获取半模式行为
MyModalViewController *targetController = [[[MyModalViewController alloc] init] autorelease]; targetController.modalPresentationStyle = UIModalPresentationFormSheet; targetController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; //transition shouldn't matter [self presentModalViewController:targetController animated:YES]; targetController.view.superview.frame = CGRectMake(0,44/*navigation bar's height*/,height, width);//it's important to do this after // use full screen height and width here targetController.view.superview.center = self.view.center;
答案 3 :(得分:0)
使用此行not presentModelViewController
[self presentViewController:vc animated:YES completion:Nil];
答案 4 :(得分:0)
也许这样的东西对你有用(自我是UINavigationController):
- (void)verticalPushViewController:(UIViewController *)controller
{
[UIApplication sharedApplication].keyWindow.backgroundColor = [UIColor colorWithWhite:1 alpha:0.9];
CATransition* transition = [CATransition animation];
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
transition.duration = 0.3;
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromTop;
[self.view.layer addAnimation:transition forKey:kCATransition];
[self pushViewController:controller animated:NO];
}
- (UIViewController *)verticalPopViewController
{
[UIApplication sharedApplication].keyWindow.backgroundColor = [UIColor colorWithWhite:1 alpha:0.9];
CATransition* transition = [CATransition animation];
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
transition.duration = 0.3;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromBottom;
[self.view.layer addAnimation:transition forKey:kCATransition];
return [self popViewControllerAnimated:NO];
}
答案 5 :(得分:-1)
最简单的方法。
呈现
LaunchImageViewController *launchView = [self.storyboard instantiateViewControllerWithIdentifier:@"launchImage"];
[[UIApplication sharedApplication].keyWindow addSubview:launchView.view];
关闭。我在里面调用了这个(LaunchImageViewController)。
[self.view removeFromSuperview];