UIActionSheet将无法在横向模式下正确显示

kat*_*yte 3 iphone landscape orientation uiactionsheet

我正在尝试在我的应用程序中显示UIActionsheet.它在纵向模式下完美运行,但当我尝试以横向方向显示时,它仍然从底部滑入.但是它不再使用带有拾取器控件的按钮和显示器,就像在横向模式下一样.它处于错误的位置.

我不使用自动旋转并将所有内容保持在纵向模式.偶尔我会以横向模式显示内容,并希望动作表正确显示.

我正在设置状态栏方向......

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];
Run Code Online (Sandbox Code Playgroud)

当我处于"横向模式"时,状态栏始终显示正确.如果我显示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];
Run Code Online (Sandbox Code Playgroud)

我还试图从应用程序委托和工具栏中显示它.如果我在显示之前设置状态栏方向仍然不起作用.我甚至试过了.

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeLeft];
Run Code Online (Sandbox Code Playgroud)

有没有人知道为什么动作表可能显示在错误的位置但是有正确的控件?或者如何强制动作表显示在特定位置.我宁愿不必实现我自己的动作表版本来让它显示正确.

提前致谢.

编辑/解决方案:强制操作表以横向模式显示

以下是我如何设法让它工作,我创建了一个横向视图并将其添加到我的主窗口,如下所示:

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];
Run Code Online (Sandbox Code Playgroud)

然后像这样显示我的行动表

if (landscape) {
    [menu showInView:landscapeView];
} else {
    [menu showInView:self.view];
}
Run Code Online (Sandbox Code Playgroud)

非常感谢tc.在这里指出我正确的方向.

Dwa*_*ill 13

我有类似的问题.我的工具栏中有一个按钮,显示一个操作表.显示Action Sheet的代码在我的rootViewController中.使用以下代码在横向模式下显示不正确:

[actionSheet showInView:[self.view]];
Run Code Online (Sandbox Code Playgroud)

此更改纠正了此问题:

[actionSheet showInView:[self.navigationController view] ];
Run Code Online (Sandbox Code Playgroud)

似乎ActionSheet从传递到ShowInView的视图中获取它的方向,并且我的rootViewController处于纵向模式,即使我当前的视图是在Landscape中.至少,这是我的理论.