UIDevice的beginGeneratingDeviceOrientationNotifications无法正常工作

4

我有一个UIView的子类中包含一个子视图。当设备旋转时,我希望该子视图被移除。这是我的代码:

- (void)awakeFromNib
{
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

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

}

- (void)orientationChanged
{
    [subview removeFromSuperview];
}

我的问题是,即使设备稍微倾斜一点,或者放在桌子上,子视图也会消失。我该怎么做才能防止这种情况发生?


你的应用程序支持多个界面方向吗? - rob mayoff
1个回答

6
不要追踪设备方向。请追踪界面方向。使用UIApplicationWillChangeStatusBarOrientationNotification代替UIDeviceOrientationDidChangeNotification,并从通知的userInfo中获取新的界面方向。(如果跟踪界面方向,则不需要执行beginGeneratingDeviceOrientationNotifications。)

有没有办法强制调用它?当设备处于竖屏模式时,我需要显示一个竖屏视图版本,但默认设置是横屏... - LightningStryk

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接