Reputation: 23
I am working on UI issue of ipad app development (about image). I have read some documents on apple development site but i cannot find any information about it.
Is there any file convention for image files to distinguish which image the system should load for Landscape/Portrait. Because I see that for launching image, we can use "MyLaunchImage-Portrait.png" & "MyLaunchImage-Lanscape.png". I have tried to add "-Landscape", "-Portrait", "-Landscape~ipad", "-Portrait~ipad" to other images for general use but it fails.
Is there anyone who has encountered this issue before?
Upvotes: 2
Views: 2294
Reputation: 130193
Unfortunately there is not standard convention for this other than the iPad's launch images. However, you can use NSNotificationCenter
to listen for orientation change events and respond to them accordingly. Here's an example:
- (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;
}
}
Upvotes: 1