【发布时间】:2015-01-17 16:30:21
【问题描述】:
从UIAlertController 显示视图会将警报移动到屏幕左上角的错误位置。 iOS 8.1、设备和模拟器。
当我们尝试从当前“最顶层”视图呈现视图时,我们在应用中注意到了这一点。如果 UIAlertController 恰好是最顶层的视图,我们就会得到这种行为。我们已将代码更改为简单地忽略 UIAlertControllers,但我发布此内容以防其他人遇到同样的问题(因为我找不到任何东西)。
我们已将其隔离为一个简单的测试项目,完整代码在此问题的底部。
- 在新的 Single View Xcode 项目中的 View Controller 上实现
viewDidAppear:。 - 发送
UIAlertController提醒。 - 警报控制器立即调用
presentViewController:animated:completion:显示然后关闭另一个视图控制器:
presentViewController:... 动画开始的那一刻,UIAlertController 移动到屏幕的左上角:
dismissViewControllerAnimated: 动画结束时,警报已被进一步移动到屏幕的左上角:
完整代码:
- (void)viewDidAppear:(BOOL)animated {
// Display a UIAlertController alert
NSString *message = @"This UIAlertController will be moved to the top of the screen if it calls `presentViewController:`";
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"UIAlertController iOS 8.1" message:message preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"I think that's a Bug" style:UIAlertActionStyleCancel handler:nil]];
[self presentViewController:alert animated:YES completion:nil];
// The UIAlertController should Present and then Dismiss a view
UIViewController *viewController = [[UIViewController alloc] init];
viewController.view.backgroundColor = self.view.tintColor;
[alert presentViewController:viewController animated:YES completion:^{
dispatch_after(0, dispatch_get_main_queue(), ^{
[viewController dismissViewControllerAnimated:YES completion:nil];
});
}];
// RESULT:
// UIAlertController has been moved to the top of the screen.
// http://i.imgur.com/KtZobuK.png
}
上面的代码中有什么会导致这个问题吗?是否存在任何替代方案可以允许从 UIAlertController 无错误地呈现视图?
rdar://19037589
http://openradar.appspot.com/19037589
【问题讨论】:
-
奇怪的行为,感谢指出错误
标签: ios cocoa-touch ios8 uialertview uialertcontroller