我有一个UIView,其中包含许多项目,如UIScrollView。
当我更改设备(或iPhone模拟器)的位置时,如何指定我想要旋转仅一个 UIScrollView?
谢谢!
答案 0 :(得分:3)
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
self.theView.transform = CGAffineTransformIdentity;
self.theView.transform = CGAffineTransformMakeRotation(degreesToRadians(-90));
答案 1 :(得分:1)
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;
}
}
祝你好运,:D