告诉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.