Programmatically scroll a UIScrollView

2020-01-26 12:45发布

I have a UIScrollView which has several views. When a user flicks their finger, the view scrolls to the right or left depending on the direction of the finger flick. Basically my code works in a way similar to the iPhone photo app. Now, is there a way that I can programmatically do the same thing so that I end up with a slideshow that runs on its own with a click of a button and a configurable pause between each scroll?

How do you really do slideshows with UIScrollView?

9条回答
老娘就宠你
2楼-- · 2020-01-26 13:39

Swift 3

   let point = CGPoint(x: 0, y: 200) // 200 or any value you like.
    scrollView.contentOffset = point
查看更多
够拽才男人
3楼-- · 2020-01-26 13:42

With Animation in Swift

scrollView.setContentOffset(CGPointMake(x, y), animated: true)
查看更多
成全新的幸福
4楼-- · 2020-01-26 13:42
scrollView.setContentOffset(CGPoint(x: y, y: x), animated: true)
查看更多
登录 后发表回答