强制 UIAlertView 进入横向模式
我需要以横向模式显示 UIAlertView。我尝试了显而易见的方法,在 willPresentAlertView:
委托方法中设置转换,但无济于事:
-(void) willPresentAlertView:(UIAlertView *)alertView {
alertView.transform = CGAffineTransformMakeRotation(M_PI_2);
}
有关如何解决此问题的任何建议吗?
I need to display a UIAlertView in landscape mode. I tried the obvious, setting the transform in the willPresentAlertView:
delegate method to no avail:
-(void) willPresentAlertView:(UIAlertView *)alertView {
alertView.transform = CGAffineTransformMakeRotation(M_PI_2);
}
Any suggestions on how to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您是否在
didPresentAlertView
中尝试过?Have you tried in the
didPresentAlertView
?如果您使用
UIViewController
,它应该会自动旋转。您是否忘记在
shouldAutorotateToInterfaceOrientation
中返回YES
以获得所需的方向?It should rotate automatically if you're using
UIViewController
.Did you forget to return
YES
for the desired orientations inshouldAutorotateToInterfaceOrientation
?显示警报的视图的方向是什么?我遇到了同样的问题,我尝试在横向视图中显示 UIAlertView 但总是以纵向显示。因此,我强制调整状态栏的方向:
这对我有用。
What is the orientation of the view that shows the alert? I had the same problem, I tried to show an UIAlertView inside a landscape view but always appeared in portrait orientation. So, I forced the orientation of the status bar:
That worked to me.
在Alert Window出现之前,设置当前窗口显示在顶部。如果不这样做,您可以看到警报窗口的旋转动画。
旋转警报窗口
旋转警报窗口后,将当前窗口向后移动。
Before the Alert Window appeared , Set the current window display at the top. If not do this ,you can see the alert window's rotate animate.
Rotate the Alert Window
After the Alert window rotated, move the current window back.
我最近也遇到了同样的问题。对我来说,解决方案是使用
UIAlertController
- 涵盖UIAlertview
和UIActionsheet
的旧处理。UIAlertController
,您必须在其中重载方法viewWillAppear
和viewWillDisappear
,如下例所示。AlertViewController.h
AlertViewController.m
实现在需要的地方显示警报视图的方法。
(无效)showInfoAlertView {
I was struggling with quite the same issue lately. For me solution was using
UIAlertController
- cover older handling ofUIAlertview
andUIActionsheet
.UIAlertController
, where you must overloaded methodsviewWillAppear
andviewWillDisappear
, like in example bellow.AlertViewController.h
AlertViewController.m
implement method for showing alert view where you needed.
(void) showInfoAlertView {