gpt4 book ai didi

ios - UICollisionBehavior 边界不起作用

转载 作者:搜寻专家 更新时间:2023-10-31 22:07:55 26 4
gpt4 key购买 nike

我在导航 Controller 中有一个 View 。

然后我向该 View 添加一个 subview 并偏移其原点高度,使其仅覆盖屏幕的一半(另一半溢出屏幕底部)。然后我希望能够向上拖动此 View ,但当它到达导航栏底部时它会停止。

我正在使用 UIPanGestureRecognizer 来处理 View 的拖动,这工作正常,但它似乎不会在边界处停止。

这是我正在使用的代码:

bottomNavbarY = UIApplication.sharedApplication().statusBarFrame.size.height + self.navigationController!.navigationBar.frame.size.height

view.addSubview(pullover.view)
pullover.view.frame.origin.y = pulloverOffset

var animator = UIDynamicAnimator(referenceView: view)
var collision = UICollisionBehavior(items: [pullover.view])
collision.translatesReferenceBoundsIntoBoundary = true
collision.addBoundaryWithIdentifier("upper", fromPoint: CGPointMake(0, bottomNavbarY), toPoint: CGPointMake(UIScreen.mainScreen().bounds.size.width, bottomNavbarY))
animator.addBehavior(collision)

但是,当我向上拖动覆盖 View 时,它不会与任何边界交互,它只是直接穿过。我究竟做错了什么?是否可以使用边界来阻止用户以这种方式拖动的 View ?

最佳答案

when I drag the covering view up it never interacts with any boundary

您误解了此功能。碰撞边界用于 UIKit Dynamics 负责移动 View 的情况。拖动是指用户负责移动 View 。如果您希望拖动在某个点停止,则由您在手势识别器处理程序中考虑 View 的位置,如果您不希望它移动,则不要移动 View 。

关于ios - UICollisionBehavior 边界不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31326643/

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