如何只旋转UIView中的一个元素

时间:2011-02-17 15:14:46

标签: iphone objective-c

我有一个UIView,其中包含许多项目,如UIScrollView。

当我更改设备(或iPhone模拟器)的位置时,如何指定我想要旋转仅一个 UIScrollView?

谢谢!

2 个答案:

答案 0 :(得分:3)

  • 返回NO

- (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