Authorize root mode when device is rotated

I am developing a PDF reader. I am facing a problem while rotating the simulator. What I do when the view is loaded by the ViewController (i.e. In the loadView ), I create a UIScrollView that contains the UIImageView and UIView the same size (i.e. the size of the PDF file page). It works great in portrait mode. But when I rotate the simulator in landscape mode, the view does not autoresist according to the device. I tried

 self.view.autoresizesSubviews = YES; self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 

in viewDidLoad() ViewController

But it does not work. I am confused how these two properties work. I think that these properties will autoresist the UIScrollView to the size of the root view in which I load the UIScrollView . But what to do to automate the main view into which the UIScrollView is loaded?

+4
source share
2 answers

This is the end of the answer ... It may help if you have not fixed it yet.

When you create any application in portraid mode, and if you want to rotate (resize) it to landscape mode, you must do it in the User Interface Builder or .xib file (or in the iPad or iPhone Storyboard file).

So, to check or check the rotation in the simulator:

  • Go to "CUSTOM INTERFACE BUILDER" or the ".XIB" file (or the "Splitting iPad or iPhone").

  • Then select “UIImageView” and go to “SHOW ATTRIBUES INSPECTORS”.

  • In the fourth tab (Attributes Inspector), set the Aspect Fit mode, and on the third tab (Inspector) and the fifth tab (Inspector Size) set the auto-detection attributes as follows:

Set arrows in all directions. Sorry, I can’t upload the image.

  • Do the same for UIView (3).

  • Before moving on, you can double-check that you got all the autoplay attributes by selecting "Detailed view of the controller" and changing the orientation from "Portrait to landscape": "Sorry, I can’t upload the image at the moment."

  • You can check or change to "Landscape or portrait" in the upper right part of the "Simulated indicators" in the "Size" section, select "Orientation".

If something is wrong, do not worry: just change it to a portrait and double-check the settings.

0
source

I had the same problem when trying to use auto resize methods. So I hope this helps. (PS I assume that you are creating the user interface programmatically and not through IB)

So have you tried this?

Inside your view manager, add the following:

// Set the View Controller to fit the whole screen. -(BOOL)wantsFullScreenLayout{ return YES; }

Inside the loadView method, change your scrollView to:

 // set the initial size of your scrollView object. [scrollView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; // Set the auto resizing attributes. [scrollView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight]; 

In addition to this, you may need to set the autoresizingmask fields for a UIView or UIImageView depending on the type of layout you need when the device is rotated.

0
source

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


All Articles