简体   繁体   English

如何使用不同的页面大小创建UIScrollView(页面捕捉,弹跳)

[英]How to create UIScrollView with different page sizes (page snapping, bounce)

I'm trying to create custom vertical UIScrollView which could handle multiple pages with different page heights. 我正在尝试创建自定义垂直UIScrollView,它可以处理具有不同页面高度的多个页面。

Assumptions: 假设:

  • page height is equal or greater than screen height 页面高度等于或大于屏幕高度
  • if page is taller than screen height, it scrolls as usual UIScrollView – with bouncing on top and bottom 如果页面高于屏幕高度,它会像往常一样滚动UIScrollView - 在顶部和底部弹跳
  • if user ends up scrolling and "page break" is in the middle of screen 如果用户最终滚动并且“分页符”在屏幕中间
    • if there is no velocity - page snaps to closest 如果没有速度 - 页面快照到最近
    • if there is velocity - page changes to one in direction of swipe 如果有速度 - 页面更改为滑动方向

I've tried many approaches to achieve this, but I've stumbled upon many UIScrollView quirks, which make it hard. 我已经尝试了很多方法来实现这一点,但我偶然发现了许多UIScrollView怪癖,这让它变得困难。

Problems: 问题:

  • UIPanGestureRecognizer has unreliable method for getting velocity (velocityInView:) UIPanGestureRecognizer有获取速度的不可靠方法(velocityInView :)
  • scrollViewWillEndDragging:withVelocity:targetContentOffset: method gives me headache, because it arbitrarily can destroy my attempts to animate setting content offset scrollViewWillEndDragging:withVelocity:targetContentOffset:方法让我很头疼,因为它任意可以破坏我设置内容偏移动画的尝试
  • I don't know how to achieve bounce in one of the middle pages, I'm afraid i would have to rewrite whole scrolling handling 我不知道如何在其中一个中间页面实现反弹,我担心我不得不重写整个滚动处理
  • when I try to override setting content offset when UIScrollView is decelerating, what I get is 当我尝试在UIScrollView减速时覆盖设置内容偏移时,我得到的是
    • my content offset is set 我的内容偏移已设置
    • deceleration continues beyond content offset I set 减速继续超出我设定的内容偏移

Bonus 奖金

I have also tried putting UIScrollView inside UIScrollView as a page, but this approach was also pain in the neck. 我也尝试将UIScrollView放在UIScrollView中作为一个页面,但这种方法也是痛苦的。 For example when I was at the bottom of inside scroll, then i scrolled down a bit, put my finger away and quickly grabbed again and scrolled upwards, the outer scroll received touch, which messed up inside scroll presentation. 例如,当我在内部滚动的底部时,然后我向下滚动了一下,将我的手指放开并再次快速抓住并向上滚动,外部滚动接收到触摸,这在滚动演示内部搞砸了。

Does somebody have any idea how to do this? 有人知道怎么做吗? Any tips will be helpful as I'm completely stuck... 任何提示都会有所帮助,因为我完全陷入困境......

Try this. 试试这个。 Might help. 可能有帮助。 Based on the Circa news app. 基于Circa新闻应用程序。

https://www.cocoacontrols.com/controls/rscircapagecontrol https://www.cocoacontrols.com/controls/rscircapagecontrol

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM