我试图检测任何设备方向的改变,以便更新视图。
我想在横屏或竖屏模式下均更新视图,因此我实现了以下方法:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
我知道如果要更新视图以正确显示当前方向,我需要实现以下方法之一:
– willRotateToInterfaceOrientation:duration:
– willAnimateRotationToInterfaceOrientation:duration:
– didRotateFromInterfaceOrientation:
– willAnimateFirstHalfOfRotationToInterfaceOrientation:duration:
– didAnimateFirstHalfOfRotationToInterfaceOrientation:
– willAnimateSecondHalfOfRotationFromInterfaceOrientation:duration:
现在的问题是,我不明白为什么当我旋转模拟器时,这些方法都没有被触发。
我也尝试了这段代码:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
但仍然没有任何反应。所以我想知道,模拟器是否会发出旋转通知?如果是,那我做错了什么?