我制作了一个简单的单屏应用程序,它在屏幕左侧有一个自定义LadderView,右侧有一个TableView,还有一个滑动ChartView,位于LadderView下方,可以拖动到显示在TableView上。
ChartView中的设置代码如下所示:
func setup () {
let screenHeight = self.superview!.frame.size.height
let screenWidth = self.superview!.frame.size.width
self.panGestureReconizer = UIPanGestureRecognizer(target: self, action: #selector(GraphCentreView.handlePan(_:)))
panGestureReconizer.cancelsTouchesInView = false
self.addGestureRecognizer(panGestureReconizer)
self.animator = UIDynamicAnimator(referenceView: self.superview!)
self.dynamicItem = UIDynamicItemBehavior(items: [self])
self.dynamicItem.allowsRotation = false
self.dynamicItem.elasticity = 0
snap = UISnapBehavior(item: self, snapToPoint: CGPoint(x: -screenWidth + 80, y: screenHeight / 2))
animator.addBehavior(snap)
self.gravity = UIGravityBehavior(items: [self])
self.gravity.gravityDirection = CGVectorMake(-5, 0)
self.container = UICollisionBehavior(items: [self])
self.container.addBoundaryWithIdentifier("leftmost", fromPoint: CGPointMake(-self.frame.size.width + 80, 0), toPoint: CGPointMake(-self.frame.size.width + 80, screenHeight))
container.addBoundaryWithIdentifier("rightmost", fromPoint: CGPointMake(screenWidth, 0), toPoint: CGPointMake(screenWidth, screenHeight))
animator.addBehavior(gravity)
animator.addBehavior(dynamicItem)
animator.addBehavior(container)
}
ChartView的约束设置为捕捉到superView的顶部和底部布局指南。但是,问题是ChartView稍微向上移动了。我已经完成了我的代码一千次,但我找不到任何会弄乱GraphView的y坐标的东西。但是,当我不将这些行为添加到动画师时,根据约束条件,视图放置得很好。你能帮我找到问题吗?