我正在尝试在我的应用程序中显示一个UIActionsheet。在竖屏模式下,它可以完美地工作。但是当我尝试在横屏模式下显示时,它仍然从底部滑入。然而,它不再使用按钮,并像处于横屏模式下一样显示选择器控件。只是位置不对。
我不使用自动旋转,在竖屏模式下保持一切。偶尔我会以横屏模式显示一些内容,并希望操作表能正确显示。
我这样设置状态栏方向...
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];
当我处于横向模式时,状态栏始终正确显示。如果我显示一个AlertView,它也可以正确显示。然后我像这样显示actionsheet:
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];
我还尝试过从app delegate和工具栏中显示它。如果我在显示之前设置状态栏方向,它仍然不起作用。我甚至已经尝试了。
[[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.在这里指引我方向。
CGRectMake(0, 0, 480, 380);
- mahboudz