【问题标题】:How to show a UIPageControl on top of a fullscreen ChildViewController?如何在全屏 ChildViewController 上显示 UIPageControl?
【发布时间】:2014-03-12 16:22:42
【问题描述】:

在许多应用的介绍屏幕中,您都有一个位于全屏图像顶部的 UIPageControl(底部没有黑色边框)。

我不知道这是怎么做到的。我是否正确将 UIPageControl 添加为 ChildViewController 的子视图?一旦用户滑动到下一个屏幕,页面控件如何不移动?

谢谢

【问题讨论】:

    标签: uiscrollview uipageviewcontroller uipagecontrol


    【解决方案1】:

    一种方法是使用 UIPageViewController 作为您的主屏幕。实施

    -(NSInteger)presentationCountForPageViewController:(UIPageViewController *)pvc {
        //
    }
    
    -(NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pvc {
        // 
    }
    

    在您的页面视图控制器数据源中。 (请参阅文档以了解您需要为每个方法返回什么。)页面控件将神奇地出现,作为页面视图控制器的一部分,这仅仅是因为您实现了这些方法。

    不幸的是,很难看到 UIPageControl,因为默认是白底白字!我所做的是使用外观代理为其着色。例如:

    UIPageControl* proxy = [UIPageControl appearanceWhenContainedIn:[UIPageViewController class], nil];
    [proxy setPageIndicatorTintColor:[[UIColor redColor] colorWithAlphaComponent:0.6]];
    [proxy setCurrentPageIndicatorTintColor:[UIColor redColor]];
    [proxy setBackgroundColor:[UIColor yellowColor]];
    

    如果不想使用页面视图控制器,可以直接添加 UIPageControl。正如你所说的那样,它不能是 child 视图控制器的孩子,因为当我们切换到不同的孩子时它会消失。它必须是 parent 视图控制器的子节点,位于所有内容的前面。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-18
      • 1970-01-01
      • 1970-01-01
      • 2010-10-19
      相关资源
      最近更新 更多