I\'m trying to have one of the children views in my screen (owned by one view controller) not rotate when the device rotates. My view controller allows rotations as
Is your code actually executed? (Do you implement shouldAutorotateToInterfaceOrientation: ?)
stuckview.transform = CGAffineTransformMakeRotation(M_PI_2);
should do the job.
Note: The functions take radians not degrees.
To help others find this, I'm adding a couple searchable phrases, like:
prevent a UIView from rotating
prevent a UITableView background from rotating
stop a UIView rotation
stop a UITableView background rotation
A complete sample for any orientation:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
switch (toInterfaceOrientation) {
case UIInterfaceOrientationLandscapeLeft:
stuckview.transform = CGAffineTransformMakeRotation(M_PI_2); // 90 degress
break;
case UIInterfaceOrientationLandscapeRight:
stuckview.transform = CGAffineTransformMakeRotation(M_PI + M_PI_2); // 270 degrees
break;
case UIInterfaceOrientationPortraitUpsideDown:
stuckview.transform = CGAffineTransformMakeRotation(M_PI); // 180 degrees
break;
default:
stuckview.transform = CGAffineTransformMakeRotation(0.0);
break;
}
}