简体   繁体   中英

Nimbus NIPagingScrollView and Re-Layouting on Rotation

I'm using an NIPagingScrollView to display several pages on the iPhone.

Everytime I flick to a page, the next page is also pre-loaded, which is fine.

When I rotate the iPhone from Portrait to Landscape mode, I let layoutSubviews do the re-layouting in my subclass of NIPageView . The NIPagingScrollView is set to auto-stretch in width and height to stay fullscreen. This works for the current page.

But when I flick to the next page, the layout is broken, as it was prefetched before and also layouted by an automatic call to layoutSubviews .

I guess the origin is not updated right on the next page on rotation, or something like that.

Has someone a hint on how I can avoid this problem (other than not using Landscape)? And is this a bug in Nimbus?

EDIT: I discovered that NIPagingScrollView provides the methods willRotateToInterfaceOrientation:duration: and willAnimateRotationToInterfaceOrientation:duration: which should be called by the view controller. I implemented these calls, but it still does not help.

Indeed NIPagingScrollView provides those methods, but if you look at them, you'll see that the layout computations are based on the scrollview frame values.

So if you want the correct values to be given to your paging scroll view, just for example, the frame or your main view (the controller view) to the paging scroll view (_scrollView in the example).

That way, just before the animation, your paging scroll view will have the correct waited frame, and your layout will be recomputed correctly.

- (void)willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation
                                     duration: (NSTimeInterval)duration {

    // Your missing line of code to set the scroll view frame values
    [self->_scrollView setFrame:self.view.bounds];

    [self->_scrollView willAnimateRotationToInterfaceOrientation: toInterfaceOrientation
                                                        duration: duration];

    [super willAnimateRotationToInterfaceOrientation: toInterfaceOrientation
                                            duration: duration];

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM