Wil*_*sen 4 cocoa-touch objective-c orientation
我在UIView的子类中有一个子视图.旋转设备时,我希望删除子视图.这是我的代码:
- (void)awakeFromNib
{
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged) name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)orientationChanged
{
[subview removeFromSuperview];
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,即使设备稍微倾斜,或者换上例如表,子视图也会移除.我该怎么做才能防止这种情况发生?
不要跟踪设备方向.跟踪界面方向.使用UIApplicationWillChangeStatusBarOrientationNotification而不是UIDeviceOrientationDidChangeNotification,并从通知中获取新的界面方向userInfo.(beginGeneratingDeviceOrientationNotifications如果跟踪界面方向,则无需执行此操作.)
| 归档时间: |
|
| 查看次数: |
1768 次 |
| 最近记录: |