【问题标题】:Nimbus NIPagingScrollView and Re-Layouting on RotationNimbus NIPagingScrollView 和旋转重新布局
【发布时间】:2012-01-28 08:31:50
【问题描述】:

我正在使用NIPagingScrollView 在 iPhone 上显示多个页面。

每次我翻到一个页面,下一个页面也会被预加载,这很好。

当我旋转 iPhone 从纵向模式到横向模式时,我让layoutSubviews 在我的NIPageView 子类中进行重新布局。 NIPagingScrollView 设置为自动拉伸宽度和高度以保持全屏显示。这适用于当前页面。

但是当我翻到下一页时,布局被破坏了,因为它之前是预取的,并且还通过自动调用 layoutSubviews 进行布局。

我猜原点没有在下一页上的轮换页面上更新,或者类似的东西。

有人提示我如何避免这个问题(除了不使用横向)吗?这是 Nimbus 中的错误吗?

编辑: 我发现NIPagingScrollView 提供了方法willRotateToInterfaceOrientation:duration:willAnimateRotationToInterfaceOrientation:duration:,应该由视图控制器调用。我实现了这些调用,但仍然没有帮助。

【问题讨论】:

    标签: iphone ios layout autorotate nimbus-ios


    【解决方案1】:

    确实NIPagingScrollView 提供了这些方法,但是如果您查看它们,您会发现布局计算是基于滚动视图框架值的。

    因此,如果您希望为分页滚动视图提供正确的值,例如,分页滚动视图(示例中为 _scrollView)的框架或主视图(控制器视图)。

    这样,就在动画之前,您的分页滚动视图将具有正确的等待帧,并且您的布局将被正确地重新计算。

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

    【讨论】:

    • 感谢您的提示,下次处理此代码时我会尝试一下!
    猜你喜欢
    • 1970-01-01
    • 2013-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多