告诉UIPageViewController何时滚动(用于图像的视差滚动) [英] Tell When a UIPageViewController is Scrolling (for Parallax Scrolling of an Image)

查看:148
本文介绍了告诉UIPageViewController何时滚动(用于图像的视差滚动)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使效果类似于新Yahoo weather应用程序中的效果.基本上,UIPageViewController中的每个页面都有一个背景图像,并且在滚动浏览页面视图时,图像的位置仅滚动大约一半的速度.我该怎么做?我以为我可以在UIPageViewController中使用某种委托方法来获取当前偏移量,然后像这样更新图像.唯一的问题是,我仍然无法找到UIPageViewController是否正在滚动!有没有办法呢?谢谢!

I am trying to make an effect similar to that found in the new Yahoo weather app. Basically, each page in the UIPageViewController has a background image, and when scrolling through the page view, the Image's location only scrolls about half the speed. How would I do that? I thought I could use some sort of Delegate Method in the UIPageViewController to get the current offset and then update the images like that. The only problem is that I cannot find anyway to tell if the UIPageViewController is being scrolled! Is there a method for that? Thanks!

推荐答案

for (UIView *view in self.pageViewController.view.subviews) {
    if ([view isKindOfClass:[UIScrollView class]]) {
         [(UIScrollView *)view setDelegate:self];
    }
} 

这使您可以访问所有标准滚动视图API方法. 而且这没有使用私有的Apple API.

this gives you access to all standard scroll view API methods. And this is not using private Apple API's.

我添加了遍历子视图的遍历,可以100%找到UIPageViewController的内部滚动视图 警告: 请注意 scrollview.contentOffset .控制器滚动到新页面时会重置

I added traversing through subviews, to 100% find the UIPageViewController's inner scroll view WARNING: Be careful with scrollview.contentOffset. It resets as the controller scrolls to new pages

如果您需要逼真的scrollview偏移量跟踪之类的东西,最好使用UICollectionViewController,其单元格的大小应与集合视图本身相同,并启用分页.

If you need persision scrollview offset tracking and stuff like that, it would be better to use a UICollectionViewController with cells sized as the collection view itself and paging enabled.

这篇关于告诉UIPageViewController何时滚动(用于图像的视差滚动)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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