gpt4 book ai didi

ios - 如何在 scrollViewDidScroll(_ scrollView : UIScrollView) reached bottom? 之后保持 UIButton float

转载 作者:行者123 更新时间:2023-11-28 15:20:53 25 4
gpt4 key购买 nike

Current implementation of floating button

以下是当前的实现。灰色按钮漂浮在 ScrollView 上。一旦到达黄色 View ( ScrollView 的末尾),是否有办法使按钮出现。然后让它漂浮在屏幕最底部。

我正在使用以下代码:

override func scrollViewDidScroll(scrollView: UIScrollView) {

if (scrollView.contentOffset.y >= (scrollView.contentSize.height - scrollView.frame.size.height)) {
//reached bottom - how to show button below yellow
// and keep it floating as shown above
}
}

添加我目前尝试过的额外代码:

    @IBOutlet weak var btnScroll: UIButton!

var startingFrame : CGRect!
var endingFrame : CGRect!

func scrollViewDidScroll(_ scrollView: UIScrollView) {
if (scrollView.contentOffset.y >= (scrollView.contentSize.height - scrollView.frame.size.height)) && self.btnScroll.isHidden {
self.btnScroll.isHidden = false
self.btnScroll.frame = startingFrame // outside of screen somewhere in bottom
UIView.animate(withDuration: 1.0) {
self.btnScroll.frame = self.endingFrame // where it should be placed
}
}
}

func configureSizes() {
let screenSize = UIScreen.main.bounds
let screenWidth = screenSize.width
let screenHeight = screenSize.height

startingFrame = CGRect(x: 0, y: screenHeight+100, width: screenWidth, height: 100)
endingFrame = CGRect(x: 0, y: screenHeight-100, width: screenWidth, height: 100)

}

override func viewDidLoad() {
super.viewDidLoad()

configureSizes()
}

Latest image shown like this. Button is constant and doesn't move

最佳答案

如果我理解你是对的,你想把按钮放在gif上显示的位置

试试这段代码:

override func scrollViewDidScroll(scrollView: UIScrollView) {
if (scrollView.contentOffset.y >= (scrollView.contentSize.height - scrollView.frame.size.height)) && self.button.isHidden {
self.button.isHidden = false
self.button.frame = startingFrame // outside of screen somewhere in bottom
UIView.animate(withDuration: 1.0) {
self.button.frame = yourFrame // where it should be placed
}
}
}

更新

添加此代码以在动画显示之前隐藏您的按钮

override func viewDidLoad() {
super.viewDidLoad()
self.button.isHidden = true
...
}

关于ios - 如何在 scrollViewDidScroll(_ scrollView : UIScrollView) reached bottom? 之后保持 UIButton float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46027102/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com