【问题标题】:disable DeviceOrientationNotification as long as calculation is running只要计算正在运行,就禁用 DeviceOrientationNotification
【发布时间】:2013-08-15 20:26:59
【问题描述】:

我的应用正在执行计算并在图表中显示结果。当设备旋转时,会生成一个新的UIViewController,以横向视图显示图形。因此必要的参数被传递给新的 ViewController 来创建图形。 当计算仍在运行时,当设备转为横向时,应用程序会崩溃。

有没有合适的方法暂时禁用使用过的DeviceOrientationNotification

-(void)calculate
{

disable DeviceOrientationNotification

...calculation code here

enable DeviceOrientationNotification again

} 

谢谢 (不要再打我了,即使这个问题看起来很愚蠢)

【问题讨论】:

    标签: ios uiviewcontroller device-orientation


    【解决方案1】:

    在 iOS 5 和 6 中有一个回调 UIViewcontrollers 用于自动旋转。我会在您开始计算时设置一个标志,您不应该自动旋转并在完成后将其设置回来。

    //somewhere in .h or class extension or simple member variable
    @property (nonatomic) BOOL shouldRotate;
    
    // iOS 6
    - (BOOL)shouldAutorotate {
        return self.shouldRotate;
    }
    
    - (NSUInteger)supportedInterfaceOrientations {
        return UIInterfaceOrientationMaskPortrait;//Return what is supported
    }
    
    // pre-iOS 6 support
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    
        return self.shouldRotate && //other interface check;
    }
    
    -(void)calculate{
         self.shouldRotate = NO;
         //do calculation
         self.shouldRotate = YES;
    }
    

    【讨论】:

    • 我花了一段时间,因为我必须弄清楚不仅要在计算方法中,还要在启动landscapeViewController的更新方法中放置标志。现在可以了,太棒了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-19
    • 1970-01-01
    相关资源
    最近更新 更多