我正在尝试在我的应用程序中显示 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。在这里为我指明了正确的方向。