Only having one view autorotate in xcode?

前端 未结 2 667
春和景丽
春和景丽 2021-01-06 08:34

Ok so I currently have 3 views and I need only one of them to autorotate to any orientation while the rest stay in portrait. Right now my set up is a splashviewcontroller f

2条回答
  •  广开言路
    2021-01-06 09:01

    You can manually mange the rotation of any desired UIView object like so:

    EDIT:

    In the init or viewDidLoad

    - (void)viewDidLoad
    {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(rotate) name:UIDeviceOrientationDidChangeNotification object:nil];
    
        [super viewDidLoad];
    }
    
    #define degreesToRadian(x) (M_PI * (x) / 180.0)
    
    -(void)rotate{
    
        self.view.bounds = CGRectMake(0, 0, 0, 0);
    
        if ([UIDevice currentDevice].orientation == UIInterfaceOrientationPortrait){
    
    
            CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(0));
            landscapeTransform = CGAffineTransformTranslate (landscapeTransform, 0.0, 0.0);
    
            self.view.bounds = CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y, 320, 480);
    
            [self.view setTransform:landscapeTransform];
    
    
        } else if ([UIDevice currentDevice].orientation == UIInterfaceOrientationPortraitUpsideDown){
    
    
            CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(180));
            landscapeTransform = CGAffineTransformTranslate (landscapeTransform, 0.0, 0.0);
    
            self.view.bounds = CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y, 320, 480);
    
            [self.view setTransform:landscapeTransform];
    
        } else if ([UIDevice currentDevice].orientation == UIInterfaceOrientationLandscapeRight){
    
            CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(90));
    
             landscapeTransform = CGAffineTransformTranslate (landscapeTransform, 0.0, 0.0);
             self.view.bounds = CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y, 480, 320); 
    
    
            [self.view setTransform:landscapeTransform];
    
        }else if ([UIDevice currentDevice].orientation == UIInterfaceOrientationLandscapeLeft){
    
            CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(270));
    
            landscapeTransform = CGAffineTransformTranslate (landscapeTransform, 0.0, 0.0);
            self.view.bounds = CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y, 480, 320); 
    
            [self.view setTransform:landscapeTransform];
        }
    
    }
    

提交回复
热议问题