gpt4 book ai didi

ios - 用于将动态 View 捕捉到屏幕顶部、底部或中间的 UIFieldBehaviour

转载 作者:行者123 更新时间:2023-11-28 06:32:30 26 4
gpt4 key购买 nike

我使用的是可拖动 View ,它是屏幕的宽度和高度,可以根据平移手势在屏幕上上下移动。

当平移手势结束时,我希望它根据平移结束时 View 所在的位置捕捉​​到屏幕的顶部、中间或底部三个不同的 y 位置。我想要像 UIFieldBehaviour 这样的东西,其中一个力将它动画到正确的位置。

当在顶部时,整个 View 将被显示,当在底部时,应该只显示 30px,可以说,其余 View 将在屏幕下方。因此,我需要强制仅对 View 的顶部 30px 起作用。

力场行为(不好意思画错了):

enter image description here

快照行为:
enter image description here

关于如何实现这一点有什么想法吗?

最佳答案

这比我想象的要容易。我正在使用新的 UIViewPropertyAnimator,当 pan .ended 时,我只是通过将目标 y 位置与 UIScreen 的高度进行比较来检查目标 y 位置是否应该捕捉到顶部、底部或中间。

        animator!.addAnimations({
print(target.frame.origin.y)

if (target.frame.origin.y > UIScreen.main.bounds.height / 2) {
if (target.frame.origin.y > (UIScreen.main.bounds.height - 50)) {
target.frame = CGRect(x: 0, y: UIScreen.main.bounds.height - 25, width: self.view.frame.width, height: self.view.frame.height)
} else {
target.frame = CGRect(x: 0, y: UIScreen.main.bounds.height - 95, width: self.view.frame.width, height: self.view.frame.height)
}
} else {
target.frame = CGRect(x: 0, y: 120, width: self.view.frame.width, height: self.view.frame.height)
}
})
animator!.startAnimation()

关于ios - 用于将动态 View 捕捉到屏幕顶部、底部或中间的 UIFieldBehaviour,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39935540/

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