我在 iOS 8 或更高版本中遇到了一些方向问题。如果应用程序在后台并处于其他方向,同时我的应用程序的某些进程已完成,它会向用户提供 UIAlertView
然后我的 UIAlertView
方向在它处于前景。
我正在使用以下代码来锁定 alertView
方向。
-(void)didPresentAlertView:(UIAlertView *)alertView{
// UIAlertView in landscape mode
[UIView beginAnimations:@"" context:nil];
[UIView setAnimationDuration:0.1];
alertView.transform = CGAffineTransformRotate(alertView.transform, M_PI_2);
[UIView commitAnimations];
NSLog(@"didPresentCalled");
}
请给我一些建议。提前致谢。
最佳答案
UIAlertView
在 iOS 8 中已弃用,因此您需要改用 UIAlertController
。
NSString *title = @"Title";
NSString *message = @"Message";
NSString *buttonTitle = @"Dismiss";
if (NSClassFromString(@"UIAlertController") != Nil) // Yes, Nil
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:buttonTitle
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action) {
[self dismissViewControllerAnimated:YES completion:nil];
}]];
[self presentViewController:alert animated:YES completion:nil];
}
else
{
[[[UIAlertView alloc] initWithTitle:title
message:message
delegate:self
cancelButtonTitle:buttonTitle
otherButtonTitles:nil] show];
}
关于iOS - iOS 8 中的 UIAlertView/UIAlertController 方向问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27102910/