iphone - 当 modalPresentationStyle 设置为 UIModalPresentationCurrentContext 时没有动画

标签 iphone ios objective-c xcode presentmodalviewcontroller

当我将父 UINavigationControllermodalPresentationStyle 设置为 UIModalPresentationCurrentContext 来呈现我的 UIViewController 时,UIViewController 没有滑入。没有使用过渡。

这是我的代码:

UIViewController *viewController = [[UIViewController alloc] init];

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
navController.navigationBarHidden = YES;

self.navigationController.modalPresentationStyle = UIModalPresentationCurrentContext;

[self presentViewController:navController animated:YES completion:nil];

当我不设置 modalPresenttionStyle 时,一切正常。但我需要这种样式,因为我希望 UIViewController 呈现为覆盖层。

顺便说一句:当 ViewController 被关闭时,动画效果很好。

最佳答案

根据 UIViewController.h header 定义:-

/* 定义以模态方式呈现时将用于此 View Controller 的过渡样式。放 要呈现的 View Controller 上的此属性,而不是演示者。默认为 UIModalTransitionStyleCoverVertical。 */

所以你应该像这样在 presentingViewController 上应用它:-

UIViewController *viewController = [[UIViewController alloc] init];

 UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
 navController.navigationBarHidden = YES;

//Here is the change
 navController.modalPresentationStyle = UIModalPresentationCurrentContext;

[self presentViewController:navController animated:YES completion:nil];

关于iphone - 当 modalPresentationStyle 设置为 UIModalPresentationCurrentContext 时没有动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14922539/

相关文章:

iphone - 帮助着色由图像蒙版/边界定义的图层并将图像覆盖在顶部

iphone - 两行 UISegmentedControl

iphone - 在 iPhone 上向屏幕外的 FBO 写入然后读取;在模拟器上有效但在设备上无效?

objective-c - 将数据从 watchKit 发送到 iPhone 并在不启动 iOS App 的情况下获得回调

ios - iOS 中 UIImageView 的动画圆形 mask

objective-c - 如何在 iOS >= 4.0 的 Objective-C 中创建私有(private)方法和 ivars?

ios - 由于文档目录中的数据,应用程序被拒绝

iPhone SDK - 在 Web View 中打开 UITextView 中的链接

ios - 将 UIImage 传递到另一个 View Controller 的 Cell

ios - 在swift中过滤字典