我在以编程方式创建的 UIView 上添加了一个 UIDynamicAnimator。现在我想在 Storyboard 中创建 UIView,因为我想使用自动布局。有人知道我必须改变什么才能使用 Storyboard 中的 UIView 吗?
我的代码:
func showSideBar(shouldOpen:Bool){
let barWidth:CGFloat = CGFloat(self.view.bounds.size.width)
animator.removeAllBehaviors()
isSideBarOpen = shouldOpen
let gravityX:CGFloat = (shouldOpen) ? 1.5 : -1.5
let magnitude:CGFloat = (shouldOpen) ? 50 : -50
let boundaryX:CGFloat = (shouldOpen) ? barWidth : -barWidth
let gravityBehavior:UIGravityBehavior = UIGravityBehavior(items: [sideBarContainerView])
gravityBehavior.gravityDirection = CGVectorMake(gravityX, 0)
animator.addBehavior(gravityBehavior)
let collisionBehavior:UICollisionBehavior = UICollisionBehavior(items: [sideBarContainerView])
collisionBehavior.addBoundaryWithIdentifier("sideBarBoundary", fromPoint: CGPointMake(boundaryX, 20), toPoint: CGPointMake(boundaryX, view.frame.size.height))
animator.addBehavior(collisionBehavior)
let pushBehavior:UIPushBehavior = UIPushBehavior(items: [sideBarContainerView], mode: UIPushBehaviorMode.Instantaneous)
pushBehavior.magnitude = magnitude
animator.addBehavior(pushBehavior)
let sideBarBehavior:UIDynamicItemBehavior = UIDynamicItemBehavior(items: [sideBarContainerView])
sideBarBehavior.elasticity = 0.2
animator.addBehavior(sideBarBehavior)
}