Tell When a UIPageViewController is Scrolling (for Parallax Scrolling of an Image)(告诉 UIPageViewController 何时滚动(用于图像的视差滚动))
问题描述
我正在尝试制作类似于新雅虎天气应用程序中的效果.基本上,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 何时滚动(用于图像的视差滚动)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:告诉 UIPageViewController 何时滚动(用于图像的视差滚
基础教程推荐
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
