LandscapeOrientation when running didload method in c object

I made an iPad app,

It works great when I download my application in portrait mode for the first time, but when I download my application in landscape mode for the first time, it only accepts portrait mode coordinates, because inside my didLoad method I only give portrait mode coordinates.

Now you need to specify the coordinates of the landscape mode inside my didLoad method.

I tried this, inside the didLoad method

 if (interfaceOrientation == UIInterfacePortraitmode || interfaceOrientation == UIInterfaceUpsideDown) { // do this.... } else { // do this.... } 

but I cannot write a condition for if / else inside my didLoad method.

What should I do?

+4
source share
3 answers
 -(void) viewWillAppear: (BOOL) animated { [super viewWillAppear: animated]; [self adjustViewtForNewOrientation: self.interfaceOrientation]; } -(void) willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation duration: (NSTimeInterval) duration { [self adjustViewtForNewOrientation: interfaceOrientation]; } - (void) adjustViewtForNewOrientation: (UIInterfaceOrientation) orientation { if (UIInterfaceOrientationIsLandscape(orientation)) { // Do some stuff } else { // Do some other stuff } 

also call adjustViewtForNewOrientation in your ViewDidLaod () method,

+2
source

You can perform the processing as shown below -

 -(void) viewWillAppear: (BOOL) animated { [super viewWillAppear: animated]; [self updateLayoutForNewOrientation: self.interfaceOrientation]; } -(void) willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation duration: (NSTimeInterval) duration { [self updateLayoutForNewOrientation: interfaceOrientation]; } 

and then finally the user method -

 - (void) updateLayoutForNewOrientation: (UIInterfaceOrientation) orientation { if (UIInterfaceOrientationIsLandscape(orientation)) { // Do some stuff } else { // Do some other stuff } 

}

+3
source

I had a similar problem with UIScrollView. I fixed this by aligning the subzones as suggested here .

 - (void)alignSubViews { // Position all the content views at their respective page positions scrollView.contentSize = CGSizeMake(self.contentViews.count * scrollView.bounds.size.width, scrollView.bounds.size.height); NSUInteger i = 0; for (UIView *v in self.contentViews) { v.frame = CGRectMake(i * scrollView.bounds.size.width, 0, scrollView.bounds.size.width, scrollView.bounds.size.height); i++; } } - (void)viewDidLoad { [super viewDidLoad]; //Setup subviews and then align the views. [self alignSubViews]; } - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration { [self alignSubViews]; scrollView.contentOffset = CGPointMake(self.currentPage * scrollView.bounds.size.width, 0); } 
0
source

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


All Articles