3

我有一个从 tableView 开始的项目,但是当用户点击“设置”按钮时,我想为 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 的这种变化设置动画?

4

1 回答 1

4

这有点 hackie,但尝试在动画之前设置根并再次设置,以便在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];

这个解决方案对我有用。

于 2013-11-08T16:08:14.147 回答