IPad: UIPageViewController navigationOrientation

I want the orientation change of my UIPageViewController change when the orientation of my UIViewController . That is, when the device is rotated to portrait, I want navigationOrientation change from UIPageViewControllerNavigationOrientationVertical to UIPageViewControllerNavigationOrientationHorizontal .

I tried to set the navigationOrientation property while rotating the view controller, but found that the navigationOrientation property was read-only.

Here are the images I want.

Landscape view Landscape view

Portrait view enter image description here

What should I do?

+6
source share
2 answers
Good question.

I don’t know why, but it seems that Apple does not want you to change this property. Either technical reasons, or some kind of UI landmark.

In any case, if you cannot change the orientation, you should go with a different approach and use two UIPageViewControllers , each with a different navigation orientation, in which there is one delegate. Turn on the device, you will hide / show the corresponding views or you will start / release a new object on which each device will work.

BTW. You looked at the pageViewController:spineLocationForInterfaceOrientation: delegate method. It seems that Apple prefers to respond to changes in device orientation:

Discussion Use this method to change the location of the spine when the orientation of the device changes, as well as installing new view controllers and changing the two-way state.

This method is only called if the transition style is UIPageViewControllerTransitionStylePageCurl .

Please note that the Apple calendar application works with very thin pages in the portrait - it seems to be really their idea of ​​the user interface.

+3
source

I solve this problem a little differently, I inherited the UIPageViewController class and redefined initWithCoder as follows:

 - (id)initWithCoder:(NSCoder *)aDecoder { NSDictionary *options = nil; if ([self isLandscapeOrientation]) { options = [NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:UIPageViewControllerSpineLocationMid] forKey:UIPageViewControllerOptionSpineLocationKey]; } self = [super initWithCoder:aDecoder]; return [super initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:options]; } - (BOOL)isLandscapeOrientation { UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; return UIInterfaceOrientationIsLandscape(orientation); } 
0
source

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


All Articles