Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS - UIView in landscape mode is not rotating
    primarykey
    data
    text
    <p>I'm writing an app support for both iPhone &amp; iPad. In iPhone required Portrait mode, iPad required to use Landscape.</p> <p>In <strong>AppDelegate.m</strong></p> <pre><code>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) &amp;&amp; [[UIScreen mainScreen] bounds].size.height &gt; [[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) &amp;&amp; [[UIScreen mainScreen] bounds].size.height &lt; [[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; } </code></pre> <p>In <strong>PadMainViewController.m</strong></p> <pre><code>- (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)); } </code></pre> <p>The result that I get is</p> <p><img src="https://i.stack.imgur.com/eIn67.png" alt="Wierd result"></p> <p>In project summary, I already disabled the portrait mode for iPad</p> <p><img src="https://i.stack.imgur.com/kNrNV.png" alt="enter image description here"></p> <p>Any idea why the button is not rotating?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload