Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotation with AutoLayout

I'm beginner in Xcode and I'm using ios6 with autolayout.

I would like to rotate my uiviewcontroller from:

enter image description here

to:

enter image description here

I would like to prevent my bottom bar from rotating. Something very similar to Apple's camera app rotation, but whats going wrong is that everything rotates.

I tried to put some code like

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{   
    // [Bar setTransform:CGAffineTransformMakeRotation(M_PI / -2.0)];
    // [Bar setTranslatesAutoresizingMaskIntoConstraints:YES];
}
like image 841
user1697990 Avatar asked Sep 25 '12 17:09

user1697990


1 Answers

I don't know how to achieve it by IB, but you can do that by adding specific constraints through code:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
    [self.view removeConstraints:landscapeConstraints];
  } else {
    [self.view addConstraints:landscapeConstraints];
  }
}
like image 110
Chris Avatar answered Sep 22 '22 02:09

Chris