【问题标题】:How to resize UIPageViewController in landscape如何在横向调整 UIPageViewController 的大小
【发布时间】:2013-12-13 17:57:11
【问题描述】:

我在横向模式下调整 UIPageViewController 的大小时遇到​​问题。

这是我的场景:

我有一个UIViewController,其中有一个scrollview。 我以编程方式在scrollview 中添加了UIPageViewController,它在每个页面中正确显示了我的所有视图控制器。 当我将设备方向更改为横向时,我正确地更改了 scrollview 的内容大小,但 PageViewController 仅显示其内容的一半。你能帮我解决这个问题吗?

谢谢, 阿南德。

【问题讨论】:

    标签: objective-c uiscrollview ios7 uipageviewcontroller


    【解决方案1】:

    您似乎没有获得正确的设备方向,或者尝试在 viewDidLoad 函数中设置它。以下代码应该正确地将您的页面视图控制器的框架设置为当前方向。

    - (void)viewWillLayoutSubviews {
        CGRect screenFrame = [[UIScreen mainScreen] applicationFrame];
    
        if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {
            screenFrame = CGRectMake(0, 0, screenFrame.size.height, screenFrame.size.width);
        }
    
        //Please don't forget to replace _myPageViewController with your variable 
        _myPageViewController.frame = screenFrame;
    }
    

    请注意,代码是从viewWillLayoutSubviews 调用的 功能。

    【讨论】:

    • 我删除了我的应用程序中的滚动视图并用视图替换了它。所以目前我的 viewcontroller 有一个 uisegmented 控件和一个 uiview。 uiview 有一个pageviewcontroller。我仍然无法在横向模式下调整页面浏览控制器的大小。请帮我。
      我修改了您的 viewWIllLayoutSubViews 以满足我的需要:self.subView.frame = screenFrame; [[self.pageController view] setFrame:[[self subView] bounds]];
    • 我修改了你的 viewWillLayoutSubViews 以适应我的目的,现在它可以工作了。非常感谢。
    • 折腾了 3 个小时后.....终于找到了正确的解决方案。非常感谢 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多