【问题标题】:Camera App Supported Orientation?相机应用程序支持的方向?
【发布时间】:2013-07-20 18:34:06
【问题描述】:

我想和相机应用做同样的事情:看起来只支持纵向模式,但是当你旋转某些视图时,工具栏和一些控件在同一个位置时会旋转。

我试图在 PLIST 文件中禁用所有支持的方向,但这不会调用诸如 shouldRotate 之类的委托方法,或者,显然,将调用 willRotate 来执行方向更改。

当支持的方向在 PLIST 中时,iPhone 会旋转所有视图,即使我为 shouldRotate 方法返回 NO。

如何解决这样的困境?

【问题讨论】:

    标签: iphone ios objective-c uiinterfaceorientation


    【解决方案1】:

    info.plist 中,将唯一支持的方向设置为Portrait。然后,在你的viewDidLoad 方法中,添加:

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
    

    这将调用方法:

    - (void)didRotate:(NSNotification *)aNotification; {
      UIDeviceOrientation currentDeviceOrientation = [[UIDevice currentDevice] orientation];
    
      switch(currentDeviceOrientation){
        case UIDeviceOrientationPortrait:
          break;
        case UIDeviceOrientationPortraitUpsideDown:
          break;
        case UIDeviceOrientationLandscapeLeft:
          break;
        case UIDeviceOrientationLandscapeRight:
          break;
        default:
          break;
      }
    }
    

    从那里,您可以根据任何选项做任何您想做的事情。另外,不要忘记添加:

    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
    

    给你 dealloc 方法。希望有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多