旋转UIAlertView

Pet*_*ski 7 iphone uialertview device-orientation ios

我已经创建了一个自定义的UIAlertView(通过子类化并使用其show函数搞乱),它具有一些自定义子视图并且具有非标准大小.

当我创建并显示它时它工作正常,但是,当设备旋转时,警报旋转然后返回到其默认大小.

任何想法覆盖的功能 - 或者我应该调整UIViewController?

谢谢,彼得

Nil*_*nch 4

不确定强制旋转 UIAlertView 是否符合 Apple GUI 准则,但您可以通过定义状态栏来旋转它(状态栏和 UIAlertView 粘在一起)

application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;
application.statusBarOrientation = UIInterfaceOrientationLandscapeLeft;
Run Code Online (Sandbox Code Playgroud)

但 UIAlertView 是一个 UIView 就像许多其他的一样,所以试试这个:

- (void)didPresentAlertView:(UIAlertView *)alertView
{
    [UIView beginAnimations:@"" context:nil];
    [UIView setAnimationDuration:0.1];
    alertView.transform = CGAffineTransformRotate(alertView.transform, degreesToRadian(90));
    [UIView commitAnimations];
}
Run Code Online (Sandbox Code Playgroud)