我有一个UIView的子类中包含一个子视图。当设备旋转时,我希望该子视图被移除。这是我的代码:
- (void)awakeFromNib
{
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged) name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)orientationChanged
{
[subview removeFromSuperview];
}
我的问题是,即使设备稍微倾斜一点,或者放在桌子上,子视图也会消失。我该怎么做才能防止这种情况发生?