Only having one kind of autorotation in xcode?

Okay, so I currently have 3 views, and I only need one of them to autorotate any orientation while the rest remains in the portrait. At the moment, my setup is a splashview control that disappears in view A, and the inside view of A is a button to switch to view B. All I want is for view B to rotate in any orientation.

When I return YES in order to enable automatic processing in the splashview controller, each view rotates because it is a parent view. When I return a portrait only to a splashview, nothing rotates, even if other views return YES. Is there a way to only scan B rotate? I am willing to do this manually if you can provide the code. Thanks

+4
source share
2 answers

You can manually control the rotation of any desired UIView object as follows:

EDIT:

In 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]; } } 
+4
source

In the "General Goals", "Orientation of the Supported Interface" section, all elements except Upside Down are selected, so you only need to go to your .m file, which processes the view and uses this code fragment.

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } 

It helps me.

0
source

Source: https://habr.com/ru/post/1380074/


All Articles