开发者

How to rotate only one element in a UIView

开发者 https://www.devze.com 2023-02-11 22:24 出处:网络
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 Simu

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

0

精彩评论

暂无评论...
验证码 换一张
取 消