Programmatically scroll a UIScrollView

前端 未结 9 1020
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-29 15:52

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 f

相关标签:
9条回答
  • 2020-11-29 16:18

    You can scroll to some point in a scroll view with one of the following statements in Objective-C

    [scrollView setContentOffset:CGPointMake(x, y) animated:YES];
    

    or Swift

    scrollView.setContentOffset(CGPoint(x: x, y: y), animated: true)
    

    See the guide "Scrolling the Scroll View Content" from Apple as well.

    To do slideshows with UIScrollView, you arrange all images in the scroll view, set up a repeated timer, then -setContentOffset:animated: when the timer fires.

    But a more efficient approach is to use 2 image views and swap them using transitions or simply switching places when the timer fires. See iPhone Image slideshow for details.

    0 讨论(0)
  • 2020-11-29 16:19

    Another way is

    scrollView.contentOffset = CGPointMake(x,y);
    
    0 讨论(0)
  • 2020-11-29 16:25

    With Animation in Swift

    scrollView.setContentOffset(CGPointMake(x, y), animated: true)
    
    0 讨论(0)
提交回复
热议问题