Макросы определения устройства берем
в этом посте.
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor blackColor]]; //чтобы при повороте не появлялось белых полос
if (self.background == nil)
self.background = [[UIImageView alloc] init];
if (iPhone) {
if (iPhone5) {
[self.backgroundImageView setFrame:CGRectMake(0, 0, 320, 568)];
[self.backgroundImageView setImage:[UIImage imageNamed:@"bg_iphone_640x1136_portrait.png"]];
} else {
[self.backgroundImageView setFrame:CGRectMake(0, 0, 320, 480)];
[self.backgroundImageView setImage:[UIImage imageNamed:@"bg_iphone_320x480_portrait.png"]];
}
} else {
[self.backgroundImageView setFrame:CGRectMake(0, 0, 768, 1024)];
[self.backgroundImageView setImage:[UIImage imageNamed:@"bg_ipad_768x1024_portrait.png"]];
}
[self.view addSubview:self.background];
}
#pragma mark -
#pragma mark InterfaceOrientationMethods
- (NSInteger)supportedInterfaceOrientations //для iOS 6.0
{
if (iPhone) {
return UIInterfaceOrientationMaskAllButUpsideDown;
} else {
return UIInterfaceOrientationMaskAll;
}
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation //для iOS 6.0
{
return UIInterfaceOrientationPortrait;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
if (iPhone)
return (toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
else
return (UIInterfaceOrientationIsPortrait(toInterfaceOrientation) || UIInterfaceOrientationIsLandscape(toInterfaceOrientation));
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
if(UIInterfaceOrientationIsPortrait(toInterfaceOrientation)){
if (iPhone) {
if (iPhone5) {
[self.backgroundImageView setFrame:CGRectMake(0, 0, 320, 568)];
[self.backgroundImageView setImage:[UIImage imageNamed:@"bg_iphone_640x1136_portrait.png"]];
} else {
[self.backgroundImageView setFrame:CGRectMake(0, 0, 320, 480)];
[self.backgroundImageView setImage:[UIImage imageNamed:@"bg_iphone_320x480_portrait.png"]];
}
} else {
[self.backgroundImageView setFrame:CGRectMake(0, 0, 768, 1024)];
[self.backgroundImageView setImage:[UIImage imageNamed:@"bg_ipad_768x1024_portrait.png"]];
}
} else if(UIInterfaceOrientationIsLandscape(toInterfaceOrientation)){
if (iPhone) {
if (iPhone5) {
[self.backgroundImageView setFrame:CGRectMake(0, 0, 568, 320)];
[self.backgroundImageView setImage:[UIImage imageNamed:@"bg_iphone_640x1136_landscape.png"]];
} else {
[self.backgroundImageView setFrame:CGRectMake(0, 0, 480, 320)];
[self.backgroundImageView setImage:[UIImage imageNamed:@"bg_iphone_320x480_landscape.png"]];
}
} else {
[self.backgroundImageView setFrame:CGRectMake(0, 0, 1024, 768)];
[self.backgroundImageView setImage:[UIImage imageNamed:@"bg_ipad_768x1024_landscape.png"]];
}
}
}