我有一个以tableView开头的项目,但是当用户点击Setup按钮时,我想将更改设置为splitViewController的动画。
我可以轻松更改rootViewController,但动画并不像宣传的那样:
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"SetupViewController"];
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[UIView transitionWithView:self.navigationController.view
duration:0.75
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
app.window.rootViewController = controller;
}
completion:nil];
我有没有办法为rootViewController的这个变化设置动画?
答案 0 :(得分:4)
这是一个小hackie,但尝试在动画之前设置root并再次返回,所以当你开始动画时新的ViewController
得到正确的大小:
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"SetupViewController"];
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
UIViewController *currentController = app.window.rootViewController;
app.window.rootViewController = controller;
app.window.rootViewController = currentController;
[UIView transitionWithView:self.navigationController.view.window
duration:0.75
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
app.window.rootViewController = controller;
}
completion:nil];
这个解决方案对我有用。