简体   繁体   English

UICollisionBehavior边界不起作用

[英]UICollisionBehavior boundary not working

I've got a view within a navigation controller. 我在导航控制器中有一个视图。

I am then adding a subview to this view and offsetting its origin height so that it covers only half the screen (with the other half overflowing off out the bottom of the screen). 然后我在这个视图中添加一个子视图并偏移其原点高度,使其仅覆盖屏幕的一半(另一半从屏幕底部溢出)。 I want to be able to then drag this view upwards but it get stopped when it hits the bottom of the navigation bar. 我希望能够向上拖动此视图,但是当它到达导航栏的底部时会停止。

I'm using a UIPanGestureRecognizer to handle the dragging of the view and this works fine but it just won't seem to stop at the boundary. 我正在使用UIPanGestureRecognizer来处理视图的拖动,这很好但它似乎不会停在边界。

This is the code I'm using: 这是我正在使用的代码:

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)

However, when I drag the covering view up it never interacts with any boundary, it just passes straight through. 然而,当我向上拖动覆盖视图时,它从不与任何边界相互作用,它只是直接通过。 What am I doing wrong? 我究竟做错了什么? Is it possible to use boundaries to stop views that are being dragged by the user in this way? 是否可以使用边界来停止以这种方式被用户拖动的视图?

when I drag the covering view up it never interacts with any boundary 当我向上拖动覆盖视图时,它永远不会与任何边界相互作用

You've misunderstood this feature. 你误解了这个功能。 Collision boundaries are for when UIKit Dynamics is in charge of moving views around. 碰撞边界适用于UIKit Dynamics负责移动视图的时候。 Dragging is when the user is in charge of moving views around. 拖动是指用户负责移动视图时。 If you want the drag to stop at a certain point, it's up to you to in the gesture recognizer handler to think about where the view is and not move the view if you don't want it to move. 如果您希望拖动停在某一点,则由您在手势识别器处理程序中考虑视图的位置,如果您不希望它移动,则不移动视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM