[英]UICollisionBehavior and UIGravityBehavior not working as expected with DispatchQueue
[英]UICollisionBehavior boundary not working
我在导航控制器中有一个视图。
然后我在这个视图中添加一个子视图并偏移其原点高度,使其仅覆盖屏幕的一半(另一半从屏幕底部溢出)。 我希望能够向上拖动此视图,但是当它到达导航栏的底部时会停止。
我正在使用UIPanGestureRecognizer
来处理视图的拖动,这很好但它似乎不会停在边界。
这是我正在使用的代码:
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)
然而,当我向上拖动覆盖视图时,它从不与任何边界相互作用,它只是直接通过。 我究竟做错了什么? 是否可以使用边界来停止以这种方式被用户拖动的视图?
当我向上拖动覆盖视图时,它永远不会与任何边界相互作用
你误解了这个功能。 碰撞边界适用于UIKit Dynamics负责移动视图的时候。 拖动是指用户负责移动视图时。 如果您希望拖动停在某一点,则由您在手势识别器处理程序中考虑视图的位置,如果您不希望它移动,则不移动视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.