Calling presentViewController:animated:completion:
does not animate in iOS7. The view just instantly appears. Animation works properly in iOS8. The present method is called in three different places in my app and they all display this behavior. It happens on both device and simulator.
调用presentViewController:animated:completion:在iOS7中没有动画。视图立即出现。动画在iOS8中正常运行。在我的应用程序中的三个不同位置调用本方法,它们都显示此行为。它发生在设备和模拟器上。
The subsequent call to dismissViewControllerAnimated:completion:
animates properly in all iOS versions.
随后调用dismissViewControllerAnimated:completion:在所有iOS版本中正确动画。
Code Structure
The view controller calling the present method is the root view controller of a UINavigationController
, and this navigation controller is one of the viewControllers
in a UITabBarController
.
调用当前方法的视图控制器是UINavigationController的根视图控制器,该导航控制器是UITabBarController中的viewControllers之一。
Each call is simple, and is triggered by a button press. Here is one of the cases:
每次通话都很简单,按下按钮即可触发。以下是其中一个案例:
GenreViewController *controller = [[GenreViewController alloc] init]; [self presentViewController:controller animated:YES completion:nil];
GenreViewController * controller = [[GenreViewController alloc] init]; [self presentViewController:控制器动画:YES完成:nil];
Attempted Fixes
- Explicitly dispatching to the main thread
- 明确地调度到主线程
- Calling
[UIView setAnimationsEnabled:YES]
before presentation - 在演示之前调用[UIView setAnimationsEnabled:YES]
- Adding a delay to displaying the controller (just to see what would happen)
- 添加延迟以显示控制器(只是为了看看会发生什么)
In each case the behavior was unchanged.
Any help would be hugely appreciated!
在每种情况下,行为都没有改变。任何帮助将非常感谢!
UPDATE - FIX
It turns out that the UITabBarController
had the modalPresentationStyle
property being set to UIModalPresentationCurrentContext
. This will not animate in iOS7, and you must use a presentation style of UIModalPresentationFullScreen
instead.
事实证明,UITabBarController将modalPresentationStyle属性设置为UIModalPresentationCurrentContext。这不会在iOS7中生成动画,您必须使用UIModalPresentationFullScreen的演示样式。
4 个解决方案
#1
1
you may use this
你可以用这个
GenreViewController *addController = [[GenreViewController alloc]
init];
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:addController];
[self presentViewController:navigationController animated:YES completion: nil];
#2
1
It turns out that the UITabBarController
had the modalPresentationStyle
property being set to UIModalPresentationCurrentContext
. This will not animate in iOS7, and you must use a presentation style of UIModalPresentationFullScreen
instead.
事实证明,UITabBarController将modalPresentationStyle属性设置为UIModalPresentationCurrentContext。这不会在iOS7中生成动画,您必须使用UIModalPresentationFullScreen的演示样式。
#3
0
As per your comment
根据你的评论
As per my knowledge this animation is not possible without NavigationController. If you have created all the things programatically then also you needs to create NavigationController programatically and have to assign one of ViewController as a root ViewController. Then going for presentViewController.
据我所知,没有NavigationController,这个动画是不可能的。如果您以编程方式创建了所有内容,那么您还需要以编程方式创建NavigationController,并且必须将ViewController之一指定为根ViewController。然后去presentViewController。
Make Global UINavigationController in appDelegate and in didFinishLaunchingWithOptions
在appDelegate和didFinishLaunchingWithOptions中创建全局UINavigationController
InitialViewController *initialVC = [[InitialViewController alloc] init];
self.navController = [[UINavigationController alloc] initWithRootViewController:initialVC];
self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];
And Then get your Appdelegate Navigation controller in specific ViewController where you want to make presentaion.
然后在您想要制作演示文稿的特定ViewController中获取Appdelegate Navigation控制器。
May be what you have created NavigationController is improper in Navigation Hierarchy.
可能是您创建的导航层次结构中的NavigationController不正确。
#4
0
Can you check this :
你能看看这个:
GenreViewController *controller = [[GenreViewController alloc] init];
controller.view.backgroundColor = [UIColor whiteColor]; // or some color of your choice
[self presentViewController:controller animated:YES completion:nil];
And see if it works. As which I feel might be the problem while using UIViewController programatically
看看它是否有效。我认为以编程方式使用UIViewController时可能存在问题
#1
1
you may use this
你可以用这个
GenreViewController *addController = [[GenreViewController alloc]
init];
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:addController];
[self presentViewController:navigationController animated:YES completion: nil];
#2
1
It turns out that the UITabBarController
had the modalPresentationStyle
property being set to UIModalPresentationCurrentContext
. This will not animate in iOS7, and you must use a presentation style of UIModalPresentationFullScreen
instead.
事实证明,UITabBarController将modalPresentationStyle属性设置为UIModalPresentationCurrentContext。这不会在iOS7中生成动画,您必须使用UIModalPresentationFullScreen的演示样式。
#3
0
As per your comment
根据你的评论
As per my knowledge this animation is not possible without NavigationController. If you have created all the things programatically then also you needs to create NavigationController programatically and have to assign one of ViewController as a root ViewController. Then going for presentViewController.
据我所知,没有NavigationController,这个动画是不可能的。如果您以编程方式创建了所有内容,那么您还需要以编程方式创建NavigationController,并且必须将ViewController之一指定为根ViewController。然后去presentViewController。
Make Global UINavigationController in appDelegate and in didFinishLaunchingWithOptions
在appDelegate和didFinishLaunchingWithOptions中创建全局UINavigationController
InitialViewController *initialVC = [[InitialViewController alloc] init];
self.navController = [[UINavigationController alloc] initWithRootViewController:initialVC];
self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];
And Then get your Appdelegate Navigation controller in specific ViewController where you want to make presentaion.
然后在您想要制作演示文稿的特定ViewController中获取Appdelegate Navigation控制器。
May be what you have created NavigationController is improper in Navigation Hierarchy.
可能是您创建的导航层次结构中的NavigationController不正确。
#4
0
Can you check this :
你能看看这个:
GenreViewController *controller = [[GenreViewController alloc] init];
controller.view.backgroundColor = [UIColor whiteColor]; // or some color of your choice
[self presentViewController:controller animated:YES completion:nil];
And see if it works. As which I feel might be the problem while using UIViewController programatically
看看它是否有效。我认为以编程方式使用UIViewController时可能存在问题