不幸的是,除了 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;
}
}