简体   繁体   中英

IOS - How do you get current scrollview position in swift?

I have a scrollview in swift which user can scroll up and down freely. When a user scrolls, stops at somewhere and hit a button in the scroll view, how do I know the current position of the scrollview?

To be detailed, I need a

currentPosition: CGPoint

such that the scrollview will be exactly the same as it appears when I do

thisScrollView.setContentOffset(currentPosition, animated: false)

This is the current position of scrollView.

scrollView.contentOffset

contentOffset

You can use the scrollView.contentOffset.y for your visible screen in all scrollable area(ContentSize). And you can use the all scrollable are --> scrollView.contentSize.height

scrollView.contentSize.height = scrollView.contentOffset.y + scrollView.frame.size.height

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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