gpt4 book ai didi

ios - UIAlertController 在调用 `presentViewController:` 时移动到屏幕顶部的错误位置

转载 作者:IT王子 更新时间:2023-10-29 07:43:27 24 4
gpt4 key购买 nike

UIAlertController 呈现 View 会将警报移动到屏幕左上角的错误位置。 iOS 8.1、设备和模拟器。

当我们尝试从当前“最顶层” View 呈现 View 时,我们在应用程序中注意到了这一点。如果 UIAlertController 恰好是最顶层的 View ,我们就会得到这种行为。我们已经更改了我们的代码以简单地忽略 UIAlertControllers,但我发布这个以防其他人遇到同样的问题(因为我找不到任何东西)。

我们已将其隔离为一个简单的测试项目,完整代码位于该问题的底部。

  1. 在新的单 View Xcode 项目的 View Controller 上实现 viewDidAppear:
  2. 呈现一个UIAlertController 警报。
  3. Alert Controller 立即调用 presentViewController:animated:completion: 来显示然后关闭另一个 View Controller :

presentViewController:... 动画开始时,UIAlertController 被移动到屏幕的左上角:

Alert has moved to top of screen

dismissViewControllerAnimated: 动画结束时,警告已进一步移动到屏幕的左上边缘:

Alert has moved into the top-left margin of the screen

完整代码:

- (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 无错误地呈现 View 的替代方案?

雷达站://19037589
http://openradar.appspot.com/19037589

最佳答案

我遇到了这样一种情况,有时模态视图会在警报之上显示自己(我知道这很愚蠢),并且 UIAlertController 可能出现在左上角(如 2nd screenshot of the original question ),我发现了一个似乎有效的单行解决方案。对于即将在 UIAlertController 上呈现的 Controller ,更改其模态呈现样式,如下所示:

viewControllerToBePresented.modalPresentationStyle = .OverFullScreen

这应该在您调用 presentViewController(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion completion: (() -> Void)?)

之前完成

关于ios - UIAlertController 在调用 `presentViewController:` 时移动到屏幕顶部的错误位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27028983/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com