如何将UIPageControl元素放在UIPageViewController中的滑动页面之上? [英] How to put the UIPageControl element on top of the sliding pages within a UIPageViewController?

查看:488
本文介绍了如何将UIPageControl元素放在UIPageViewController中的滑动页面之上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于这个,也在stackoverflow上。



关键是要发送到自定义 UIPageControl的以下消息元素:

  [self.view bringSubviewToFront:self.pageControl]; 

AppCoda教程是此解决方案的基础



添加 UIPageControl 元素在 RootViewController 之上 - 带箭头的视图控制器。



创建一个相关的<$ ViewController.m 中的c $ c> IBOutlet 元素。



viewDidLoad 方法中,您应该添加以下代码作为添加所有子视图后调用的最后一个方法。

  [self.view bringSubviewToFront:self.pageControl]; 

要根据当前内容视图的pageIndex分配当前页面,您可以将以下内容添加到 UIPageViewControllerDataSource 方法:

   - (UIPageViewController *)pageViewController:(UIPageViewController * )pageViewController viewControllerBeforeViewController:(UIViewController *)viewController 
{
// ...
index--;
[self.pageControl setCurrentPage:index];

return [self viewControllerAtIndex:index];
}

- (UIPageViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
// ... ...
索引++;
[self.pageControl setCurrentPage:index];

// ...
return [self viewControllerAtIndex:index];
}


Regarding to this tutorial by AppCoda about how to implement a app with UIPageViewController I'd like to use a custom page control element on top of the pages instead of at the bottom.

When I just put a page control element on top of the single views which will be displayed, the logical result is that the control elements scrolls with the page view away from the screen.

How is it possible to put the control element on top of the views so the page views are full screen (like with an image) so the user can see the views underneath the fixed control element?

I attached an example screenshot - credits to AppCoda and Path:

解决方案

After further investigation and searching I found a solution, also on stackoverflow.

The key is the following message to send to a custom UIPageControl element:

[self.view bringSubviewToFront:self.pageControl];

The AppCoda tutorial is the foundation for this solution:

Add a UIPageControl element on top of the RootViewController - the view controller with the arrow.

Create a related IBOutlet element in your ViewController.m.

In the viewDidLoad method you should then add the following code as the last method you call after adding all subviews.

[self.view bringSubviewToFront:self.pageControl];

To assign the current page based on the pageIndex of the current content view you can add the following to the UIPageViewControllerDataSource methods:

- (UIPageViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
    // ...
    index--;
    [self.pageControl setCurrentPage:index];

    return [self viewControllerAtIndex:index];
}

- (UIPageViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
    // ...
    index++;
    [self.pageControl setCurrentPage:index];

    // ...
    return [self viewControllerAtIndex:index];
}

这篇关于如何将UIPageControl元素放在UIPageViewController中的滑动页面之上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆