簡體   English   中英

IOS - 如何在 swift 中獲取當前滾動視圖 position?

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

我在 swift 中有一個滾動視圖,用戶可以自由上下滾動。 當用戶滾動,停在某處並點擊滾動視圖中的按鈕時,我如何知道滾動視圖的當前 position?

要詳細,我需要一個

currentPosition: CGPoint

這樣滾動視圖將與我執行時出現的完全相同

thisScrollView.setContentOffset(currentPosition, animated: false)

這是scrollView當前的position。

scrollView.contentOffset

內容偏移量

您可以在所有可滾動區域 (ContentSize) 中為您的可見屏幕使用 scrollView.contentOffset.y。 你可以使用所有可滾動的 --> scrollView.contentSize.height

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM