How to rotate only one element in a UIView
I have a UIView which contains many items like UIScrollView.
How can I specify I want to开发者_StackOverflow中文版 rotate only one UIScrollView when I change the position of my device (or iPhone Simulator) ?
Thanks !
- return NO from
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
- handle the device rotation notification yourself:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
- and rotate just the view you want:
self.theView.transform = CGAffineTransformIdentity;
self.theView.transform = CGAffineTransformMakeRotation(degreesToRadians(-90));
UIView *localView = [mainView viewWithTag:tagOfScrollViewToRotate];
UIInterfaceOrientation deviceOrientation = [UIApplicationsharedApplication].statusBarOrientation;
float angle;
switch (deviceOrientation) {
case UIInterfaceOrientationPortraitUpsideDown:
{
angle = M_PI;
CGAffineTransform transform = CGAffineTransformMakeRotation(angle);
[localView setTransform:transform];
break;
}
case UIInterfaceOrientationLandscapeLeft:
{
angle = -M_PI/2;
CGAffineTransform transform = CGAffineTransformMakeRotation(angle);
[localView setTransform:transform];
localView.frame = CGRectMake(0, 0, 768, 1024);
break;
}
case UIInterfaceOrientationLandscapeRight:
{
angle = M_PI/2;
CGAffineTransform transform = CGAffineTransformMakeRotation(angle);
[localView setTransform:transform];
localView.frame = CGRectMake(0, 0, 768, 1024);
break;
}
default:
{
angle = 0;
break;
}
}
Good luck, :D
精彩评论