简体   繁体   English

Nimbus NIPagingScrollView和旋转时的重新布局

[英]Nimbus NIPagingScrollView and Re-Layouting on Rotation

I'm using an NIPagingScrollView to display several pages on the iPhone. 我正在使用NIPagingScrollView在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 . 当我 iPhone从纵向模式旋转到横向模式时,我可以使用layoutSubviewsNIPageView子类中进行重新布局。 The NIPagingScrollView is set to auto-stretch in width and height to stay fullscreen. NIPagingScrollView设置为在宽度和高度上自动拉伸以保持全屏显示。 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 . 但是,当我轻拂到下一页时,布局被破坏了,因为它是之前被预取的,并且还通过自动调用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? 这是Nimbus中的错误吗?

EDIT: I discovered that NIPagingScrollView provides the methods willRotateToInterfaceOrientation:duration: and willAnimateRotationToInterfaceOrientation:duration: which should be called by the view controller. 编辑:我发现NIPagingScrollView提供了方法willRotateToInterfaceOrientation:duration:willAnimateRotationToInterfaceOrientation:duration:应当由视图控制器调用。 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. NIPagingScrollView确实提供了这些方法,但是如果您看一下它们,就会发现布局计算是基于scrollview帧值的。

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). 因此,如果希望将正确的值提供给页面滚动视图,例如,将框架或主视图(控制器视图)赋予页面滚动视图(本例中为_scrollView)。

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];

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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