为什么UIActionSheet在UIInterfaceOrientationPortraitUpsideDown中是倒着显示的?
Why is UIActionSheet shown upside-down in UIInterfaceOrientationPortraitUpsideDown?
我知道 UIActionSheet
在 iOS 8 中已被弃用,但我仍然需要 API,因为我仍然以 iOS 7 为目标。
问题来了:我的应用同时支持 phone 设备的 UIInterfaceOrientationPortrait
和 UIInterfaceOrientationPortraitUpsideDown
。当我的应用程序以正常纵向显示 UIActionSheet
时,一切都很好。但是,如果设备倒置,操作 sheet 也会倒置显示,如下所示:
仅当应用程序 运行 在具有 iOS 8 的设备(或模拟器)上时,问题才存在。当应用程序 运行 在iOS 7.1 的模拟器(我还没有 iOS 7.1 的真实设备来测试)。当我的应用程序仍然使用 iOS 8 之前的 SDK 构建时,问题也从未发生过,即使该应用程序是 运行 在具有 iOS 8.
的设备上也是如此
有没有人建议我在这里可能做错了什么?有关重现该问题的最小示例,请参见下面的代码片段。我正在使用 Xcode 6.1.1 和 iOS SDK 8.1 进行编码。我保证我没有以任何方式摆弄 Xcode 应用程序包 :-)
重现问题的步骤
- 使用 "Single View Application" 模板创建一个新的 Xcode 项目
- Select 主要目标,然后在 "General" 选项卡上确保选中 "Upside Down" 设备方向
- 打开主故事板
- 将名为
doIt:
的方法添加到第一响应者
- 向视图添加一个新的 UIButton 并将按钮的 "Touch Up Inside" 事件连接到方法
最后,在ViewController.m
中添加如下代码:
- (void) doIt:(id)sender
{
UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:@"sheet title"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
[actionSheet addButtonWithTitle:@"sheet action"];
[actionSheet showInView:self.view];
}
// This override is required so that interface orientation
// to UIInterfaceOrientationPortraitUpsideDown is possible
- (NSUInteger) supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
运行应用程序,旋转并点击按钮,你应该明白我的意思了。
在 ios 8 中,我认为您最好改用 UIAlertController。这样的怪案处理起来会更好
我知道 UIActionSheet
在 iOS 8 中已被弃用,但我仍然需要 API,因为我仍然以 iOS 7 为目标。
问题来了:我的应用同时支持 phone 设备的 UIInterfaceOrientationPortrait
和 UIInterfaceOrientationPortraitUpsideDown
。当我的应用程序以正常纵向显示 UIActionSheet
时,一切都很好。但是,如果设备倒置,操作 sheet 也会倒置显示,如下所示:
仅当应用程序 运行 在具有 iOS 8 的设备(或模拟器)上时,问题才存在。当应用程序 运行 在iOS 7.1 的模拟器(我还没有 iOS 7.1 的真实设备来测试)。当我的应用程序仍然使用 iOS 8 之前的 SDK 构建时,问题也从未发生过,即使该应用程序是 运行 在具有 iOS 8.
的设备上也是如此有没有人建议我在这里可能做错了什么?有关重现该问题的最小示例,请参见下面的代码片段。我正在使用 Xcode 6.1.1 和 iOS SDK 8.1 进行编码。我保证我没有以任何方式摆弄 Xcode 应用程序包 :-)
重现问题的步骤
- 使用 "Single View Application" 模板创建一个新的 Xcode 项目
- Select 主要目标,然后在 "General" 选项卡上确保选中 "Upside Down" 设备方向
- 打开主故事板
- 将名为
doIt:
的方法添加到第一响应者 - 向视图添加一个新的 UIButton 并将按钮的 "Touch Up Inside" 事件连接到方法
最后,在ViewController.m
中添加如下代码:
- (void) doIt:(id)sender
{
UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:@"sheet title"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
[actionSheet addButtonWithTitle:@"sheet action"];
[actionSheet showInView:self.view];
}
// This override is required so that interface orientation
// to UIInterfaceOrientationPortraitUpsideDown is possible
- (NSUInteger) supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
运行应用程序,旋转并点击按钮,你应该明白我的意思了。
在 ios 8 中,我认为您最好改用 UIAlertController。这样的怪案处理起来会更好