简体   繁体   English

IOS - 如何在 swift 中获取当前滚动视图 position?

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

I have a scrollview in swift which user can scroll up and down freely.我在 swift 中有一个滚动视图,用户可以自由上下滚动。 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?当用户滚动,停在某处并点击滚动视图中的按钮时,我如何知道滚动视图的当前 position?

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当前的position。

scrollView.contentOffset

contentOffset 内容偏移量

You can use the scrollView.contentOffset.y for your visible screen in all scrollable area(ContentSize).您可以在所有可滚动区域 (ContentSize) 中为您的可见屏幕使用 scrollView.contentOffset.y。 And you can use the all scrollable are --> scrollView.contentSize.height你可以使用所有可滚动的 --> scrollView.contentSize.height

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

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

相关问题 在iOS中,如何获得CGContext的当前行宽? - In iOS, how do you get the current line width of a CGContext? 在iOS中,使用Swift,如何获取iPhone开机的时间? - In iOS, using Swift, how do you get the time of iPhone boot? iOS Swift在scrollview中更改位置 - IOS Swift changing position within scrollview iOS Swift Scrollview以编程方式设置框架位置 - iOS Swift Scrollview Set Frame Position Programmatically 如何在swift(iOS)上根据scrollview的用户当前滚动值同步/更改进度条进度 - How do I sync/change progress bar progress based on scrollview’s user current scroll value on swift(iOS) 在IOS核心音频中,您如何找到文件播放器音频单元的真实当前播放头位置? - In IOS core audio, how do you find the true current play head position of a file player audio unit? 如何在iOS中获取动画UIView的当前位置 - How to get current position of animating uiview in ios 在 React Native 中获取 ScrollView 的当前滚动位置 - Get current scroll position of ScrollView in React Native 获取 SwiftUI ScrollView 的当前滚动 position - Get the current scroll position of a SwiftUI ScrollView Swift - 如何获取 ios 设备当前语言 - Swift - how to get ios device current language
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM