UIActionSheet 在横向模式下无法正确显示
我正在尝试在我的应用程序中显示 UIActionsheet。它在纵向模式下工作得很好,但当我尝试让它以横向模式显示时,它仍然从底部滑入。但是,它不再像横向模式那样使用按钮并通过选择器控件进行显示。它只是处于错误的位置。
我不使用自动旋转并将所有内容保持为纵向模式。有时,我会以横向模式显示内容,并希望操作表能够正确显示。
我正在像这样设置状态栏方向...
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];
当我处于“横向模式”时,状态栏始终显示正确。如果我显示 AlertView,它也会正确显示。然后,我像这样显示操作表,
UIActionSheet *as = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel Button" destructiveButtonTitle:nil otherButtonTitles: @"button", nil];
as.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[as showInView:self.view];
//[as showFromToolbar:toolbar];
我也尝试从应用程序委托和工具栏显示它。如果我在显示之前设置状态栏方向,它仍然不起作用。我什至尝试过。
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeLeft];
有谁知道为什么操作表可能会显示在错误的位置但具有正确的控件?或者如何强制操作表显示在特定位置。我宁愿不必实现我自己的操作表版本来使其正确显示。
提前致谢。
编辑/解决方案:强制操作表以横向模式显示
这是我如何设法让它工作的,我创建了一个横向视图并将其添加到我的主窗口中,如下所示:
landscapeView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 480, 480)];
landscapeView.transform = CGAffineTransformMakeRotation((-1)*M_PI/2);
landscapeView.bounds = CGRectMake(0, 0, 480, 380);
[appDelegate.window addSubview:landscapeView];
然后显示我的操作像这样的表
if (landscape) {
[menu showInView:landscapeView];
} else {
[menu showInView:self.view];
}
非常感谢 tc。为我指明了正确的方向。
I am trying to display a UIActionsheet in my application. It works perfectly in portrait mode but when I try to have it display in a landscape orientation it still slides in from the bottom. However it no longer uses buttons and displays with the picker control like it is in landscape mode. Its just in the wrong position.
I don't use auto rotation and keep everything in portrait mode. Occasionally I am displaying things in a landscape mode and would like the actionsheet to appear properly.
I am setting the status bar orientation like so...
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];
When I'm in 'landscape mode', and the status bar always appears correctly. If i display an AlertView it also displays correctly. I am then displaying the actionsheet like this
UIActionSheet *as = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel Button" destructiveButtonTitle:nil otherButtonTitles: @"button", nil];
as.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[as showInView:self.view];
//[as showFromToolbar:toolbar];
I have also tried to display it from the app delegate and toolbar. If I set the statusbar orientation just before displaying it still doesn't work. I have even tried.
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeLeft];
Does anyone has any idea why the actionsheet could be displaying in the wrong position yet with the right controls? Or how to force the actionsheet to display in a particular position. I would rather not have to implement my own version of an actionsheet to have it display right.
Thanks in advance.
Edit / Solution: Force Action sheet to show in landscape mode
Here is how i managed to get it to work, i created a landscape view and added it to my main window like so:
landscapeView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 480, 480)];
landscapeView.transform = CGAffineTransformMakeRotation((-1)*M_PI/2);
landscapeView.bounds = CGRectMake(0, 0, 480, 380);
[appDelegate.window addSubview:landscapeView];
and then displayed my action sheet like this
if (landscape) {
[menu showInView:landscapeView];
} else {
[menu showInView:self.view];
}
Much thanks to tc. for pointing me in the right direction here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有类似的问题。我的工具栏中有一个显示操作表的按钮。显示操作表的代码位于我的 rootViewController 中。使用以下代码在横向模式下显示不正确:
此更改纠正了问题:
似乎 ActionSheet 从传递到 ShowInView 的视图中获取其方向,而我的 rootViewController 处于纵向模式,即使我当前的视图处于横向模式。至少,这是我的理论。
I had a similar issue. I had a button in my toolbar that displayed an action sheet. The code to display the Action Sheet was in my rootViewController. It displayed incorrectly in landscape mode with this code:
This change corrected the issue:
It seems like the ActionSheet gets it's orientation from the view passed into ShowInView and my rootViewController was in Portrait mode even though my current view was in Landscape. At least, that's my theory.
整体“界面方向”还包括当前视图变换等内容,无论 UIViewController 认为是当前方向,也可能包括其他内容;仅设置状态栏方向并不总是足够的。
self.view 是纵向吗?
The overall "interface orientation" also encompasses things like the current view transform, whatever UIViewController thinks is the current orientation, and probably other stuff too; just setting the status bar orientation is not always sufficient.
Is self.view in portrait orientation?