Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 为什么UIInterfaceOrientation肖像中的UIActionSheet是颠倒显示的?_Ios_Objective C_Ios8_Uiactionsheet - Fatal编程技术网

Ios 为什么UIInterfaceOrientation肖像中的UIActionSheet是颠倒显示的?

Ios 为什么UIInterfaceOrientation肖像中的UIActionSheet是颠倒显示的?,ios,objective-c,ios8,uiactionsheet,Ios,Objective C,Ios8,Uiactionsheet,我知道iOS 8中不推荐使用UIActionSheet,但我仍然需要API,因为我仍然以iOS 7为目标 问题是:我的应用程序同时支持手机设备的UIInterfaceOrientationPortrait和UIInterfaceOrientationPortrait Upsidedown。当我的应用程序以正常的纵向方向显示UIActionSheet时,一切正常。但是,如果设备倒置,操作表也会倒置显示,如下所示: 只有当应用程序在iOS 8设备(或模拟器)上运行时,问题才存在。当应用程序在iOS

我知道iOS 8中不推荐使用
UIActionSheet
,但我仍然需要API,因为我仍然以iOS 7为目标

问题是:我的应用程序同时支持手机设备的
UIInterfaceOrientationPortrait
UIInterfaceOrientationPortrait Upsidedown
。当我的应用程序以正常的纵向方向显示
UIActionSheet
时,一切正常。但是,如果设备倒置,操作表也会倒置显示,如下所示:

只有当应用程序在iOS 8设备(或模拟器)上运行时,问题才存在。当应用程序在iOS 7.1模拟器中运行时,问题就消失了(我还没有真正的iOS 7.1设备要测试)。当我的应用程序仍然使用iOS 8之前的SDK构建时,即使应用程序在iOS 8设备上运行,问题也从未发生过

有没有人建议我在这里做错了什么?请参阅下面的代码片段,以获取再现该问题的最简单示例。我使用Xcode 6.1.1和iOS SDK 8.1进行编码。我保证我没有以任何方式摆弄Xcode应用程序包:-)


重现问题的步骤

  • 使用“单视图应用程序”模板创建新的Xcode项目
  • 选择主目标,然后在“常规”选项卡上确保选中“倒置”设备方向
  • 打开主情节提要
  • 将名为
    doIt:
    的方法添加到第一个响应程序
  • 在视图中添加一个新的UIButton,并将该按钮的“内部润色”事件连接到该方法
  • 最后,将以下代码添加到
    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
    没有倒转到肖像方向,对吗?@mattsven是的,没错。正如您在屏幕截图中所看到的,工作表从屏幕顶部向下掉落,文本全部颠倒。如果“奇怪的情况”是指“UIActionSheet的奇怪行为”,那么我完全同意您的看法。还有alterview,在我的应用程序中8.1版本之后,这些被弃用的控制器将出现问题。@Herzube他是对的-如果它解决了这个问题,这实际上可能是解决您问题的最简单的解决方案。使用
    UIActionSheet
    处理低于iOS 8的任何内容,使用
    UIAlertViewController
    处理
    =
    @mattsven的任何内容。它确实解决了问题,所以最后我勉强听从了你和冯的建议。虽然不是很好的代码,但到目前为止,它是最实用的解决方案。