不幸的是,除了iPad的啓動圖像以外,沒有其他的標準約定。但是,您可以使用NSNotificationCenter
來偵聽方向更改事件並相應地響應它們。這裏有一個例子:
- (void)awakeFromNib
{
//isShowingLandscapeView should be a BOOL declared in your header (.h)
isShowingLandscapeView = NO;
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
}
- (void)orientationChanged:(NSNotification *)notification
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) &&
!isShowingLandscapeView)
{
[myImageView setImage:[UIImage imageNamed:@"myLandscapeImage"]];
isShowingLandscapeView = YES;
}
else if (UIDeviceOrientationIsPortrait(deviceOrientation) &&
isShowingLandscapeView)
{
[myImageView setImage:[UIImage imageNamed:@"myPortraitImage"]];
isShowingLandscapeView = NO;
}
}
這是我使用的方式,不必使用通知中心來檢測方向變化: - (無效)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation時間:(NSTimeInterval)持續時間{ } - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { } – user1653545