问题描述
当有人用擦除手势从左到右滚动内容时,我希望背景图像以不同的速度滚动到相同的方向.就像这些经典游戏在 20 年前所做的一样(记住这一点,有人吗????)
When somebody does a wipe gesture to scroll the content from left to right, I would like to have a background image scrolling into the same direction, but at a different speed. Much like what these classic games did do 20 years ago (remember that, anybody????)
推荐答案
我通过使用 两个 UIScrollView 实例完成了这个.第一个是显示实际内容的位置,第二个(在 z 顺序中位于第一个之后)是我移动较慢的背景的位置.从那里开始,顶部的 UIScrollView 附加了一个委托,当 contentOffset 更改时会收到通知.反过来,该委托以编程方式设置背景滚动条的 contentOffset,乘以一个常数以减慢相对于前景的滚动速度.因此,例如,您可能有以下内容:
I accomplished this by using two UIScrollView instances. The first is where the actual content is displayed, and the second (which is behind the first in z-order) is where I have my slower-moving background. From there the top UIScrollView has a delegate attached to it that gets notified when the contentOffset changes. That delegate, in turn, programatically sets the contentOffset of the background scroller, multiplied against a constant to slow the scroll down relative to the foreground. So, for instance, you might have something like:
// Defined as part of the delegate for the foreground UIScrollView
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
UIScrollView* scroll_view(static_cast<UIScrollView*>(bkg_scroller_m.view));
CGPoint offset(scrollView.contentOffset);
offset.x = offset.x / 3;
offset.y = offset.y / 3;
// Scroll the background scroll view by some smaller offset
scroll_view.contentOffset = offset;
}
这篇关于在 UIScrollView 上以不同的速度滚动背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)