本文介绍了当它调用`presentViewController:`时,UIAlertController被移动到屏幕顶部的错误位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

提供视图UIAlertController 将警报移动到屏幕左上角的错误位置。 iOS 8.1,设备和模拟器。



当我们尝试从当前的最顶层视图呈现视图时,我们在应用中注意到了这一点。如果一个UIAlertController恰好是最顶层的视图,我们得到这个行为。我们已经改变了我们的代码,只是忽略UIAlertControllers,但我发布,以防其他人遇到相同的问题(因为我找不到任何东西)。




  1. 实现 viewDidAppear:


  2. 提供 UIAlertController 警报。

  3. 警报控制器立即调用 presentViewController:animated:completion:显示并关闭另一个视图控制器:

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



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





完整代码:

   - (void)viewDidAppear :(BOOL)animated {
//显示一个UIAlertController警告
NSString * message = @如果UIAlertController调用`presentViewController:`,这个UIAlertController将被移动到屏幕的顶部;
UIAlertController * alert = [UIAlertController alertControllerWithTitle:@UIAlertController iOS 8.1message:message preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@我认为这是一个Bug风格:UIAlertActionStyleCancel handler:nil]];
[self presentViewController:alert animated:YES completion:nil];

//存在然后关闭视图
UIViewController * viewController = [[UIViewController alloc] init];
viewController.view.backgroundColor = self.view.tintColor;
[alert presentViewController:viewController animated:YES completed:^ {
dispatch_after(0,dispatch_get_main_queue(),^ {
[viewController dismissViewControllerAnimated:YES completion:nil];
} ;
}];

//结果:
// UIAlertController已移动到屏幕顶部。
// http://i.imgur.com/KtZobuK.png
}

上述代码中有什么会导致此问题?是否有任何替代方案可以允许从UIAlertController无错地呈现视图?



rdar:// 19037589

解决方案

被Apple关闭


Presenting a view from a UIAlertController moves the alert to a buggy position at the top-left corner of the screen. iOS 8.1, device and simulator.

We have noticed this in an app when we attempt to present a view from the current "top-most" view. If a UIAlertController happens to be the top-most view we get this behavior. We have changed our code to simply ignore UIAlertControllers, but I'm posting this in case others hit the same issue (as I couldn't find anything).

We have isolated this to a simple test project, full code at the bottom of this question.

  1. Implement viewDidAppear: on the View Controller in a new Single View Xcode project.
  2. Present aUIAlertController alert.
  3. Alert controller immediately calls presentViewController:animated:completion: to display and then dismiss another view controller:

The moment the presentViewController:... animation begins, the UIAlertController is moved to the top-left corner of the screen:

When the dismissViewControllerAnimated: animation ends, the alert has been moved even further into the top-left margin of the screen:

Full code:

- (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];

    // 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
}

Is there anything in the above code that would be causing this issue? Do any alternatives exist that would allow bug-free presentation of a view from a UIAlertController?

rdar://19037589
http://openradar.appspot.com/19037589

解决方案

rdar://19037589 was closed by Apple

这篇关于当它调用`presentViewController:`时,UIAlertController被移动到屏幕顶部的错误位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 11:01