iOS Swift : ScrollView strict dragging

﹥>﹥吖頭↗ 提交于 2019-12-11 15:13:25

问题


I have a scrollView(only horizontal scrolling) in which two collection views and want that if it is dragged/Swiped upto >= mid of screen then it should scroll forward i.e right side (show 2nd collection view) else it should be in left side(show first collection view). It should not stay half scrolled either full or none. How can i make this possible?


回答1:


To achieve a scroll snap, you want to use this UIScrollViewDelegate method:

func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>)

You'll want to set the following within this method.

targetContentOffset.pointee.x = 

Here's a tutorial link that may help explain.

Or just convert this ObjC SO answer to swift and change from vertical snapping to horizontal as it describes.



来源:https://stackoverflow.com/questions/45657533/ios-swift-scrollview-strict-dragging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!