2013-03-14 2 views
0

Я пишу поддержку приложения для iPhone & iPad. В iPhone требуется портретный режим, iPad необходимо использовать Landscape.iOS - UIView в ландшафтном режиме не вращается

В AppDelegate.m

if ([CKAppDelegate isPad]) { 
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight]; 

    CGSize size = [self getScreenSize]; 
    navigationController = [[UINavigationController alloc] initWithRootViewController:[[PadMainViewController alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)]]; 
} else { 
    CGSize size = [self getScreenSize]; 
    navigationController = [[UINavigationController alloc] initWithRootViewController:[[MainViewController alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)]]; 
} 

self.window.rootViewController = navigationController; 

... 

- (CGSize)getScreenSize 
{ 
    CGSize size; 
    if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) && [[UIScreen mainScreen] bounds].size.height > [[UIScreen mainScreen] bounds].size.width) { 
     // in Landscape mode, width always higher than height 
     size.width = [[UIScreen mainScreen] bounds].size.height; 
     size.height = [[UIScreen mainScreen] bounds].size.width; 
    } else if (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation) && [[UIScreen mainScreen] bounds].size.height < [[UIScreen mainScreen] bounds].size.width) { 
     // in Portrait mode, height always higher than width 
     size.width = [[UIScreen mainScreen] bounds].size.height; 
     size.height = [[UIScreen mainScreen] bounds].size.width; 
    } else { 
     // otherwise it is normal 
     size.height = [[UIScreen mainScreen] bounds].size.height; 
     size.width = [[UIScreen mainScreen] bounds].size.width; 
    } 
    return size; 
} 

В PadMainViewController.m

- (id)initWithFrame:(CGRect)frame 
{ 
    UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width * 0.7, frame.size.height)]; 
    leftView.backgroundColor = [UIColor cyanColor]; 

    UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width * 0.3, frame.size.height)]; 
    rightView.backgroundColor = [UIColor yellowColor]; 

    self.chopInkButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [self.chopInkButton setTitle:@"Tap to ChopInk" forState:UIControlStateNormal]; 
    self.chopInkButton.frame = CGRectMake(50, 200, 250, 44); 
    [self.chopInkButton addTarget:self action:@selector(chopInkButtonTapped:) forControlEvents:UIControlEventTouchUpInside]; 
    [rightView addSubview:self.chopInkButton]; 

    self.logoImageView.frame = CGRectMake(50, 50, 100, 100); 
    [self.logoImageView.layer setBorderColor:[[UIColor blackColor] CGColor]]; 
    [self.logoImageView.layer setBorderWidth:2.0f]; 
    [rightView addSubview:self.logoImageView]; 

    [self.view addSubview:leftView]; 
    [self.view addSubview:rightView]; 
    return self; 
} 
... 
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation 
{ 
    return (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)); 
} 

В результате я получаю

Wierd result

В заключение проекта, я уже отключил портретный режим для IPad

enter image description here

Любая идея, почему кнопка не вращается?

ответ

0

Я решить эту проблему путем изменения

PadMainViewController.m

- (id)initWithFrame:(CGRect)frame 
{ 
    ... 
    return self; 
} 

в

- (id)initWithFrame:(CGRect)frame 
{ 
    if ((self = [super init])) { 
     ... 
    } 
    return self; 
} 

Кстати, initWithFrame является самоопределенной функцией.

0

Попробуйте использовать ниже методов: для IOS 6

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskAll; 
} 

- (BOOL)shouldAutorotate 
{ 
    return YES; 
} 
+0

все еще не работает. Кстати, я установил цель развертывания на 5.0 –

Смежные вопросы