BendableView
是一个 UIView
子类,当其位置变化动画时弯曲其边缘。内部,BendableView
包含 CAShapeLayer
,充当其背景。层在动画过程中更改其 path
,从而产生弯曲的效果。子视图保持完整。您可以在我的博客上找到更详细的描述:[Recreating Skype’s Action Sheet Animation](http://holko.pl/2014/06/26/recreating-skypes-action-sheet-animation/) 和 [Follow-Up Post](http://holko.pl/2014/06/28/action-sheet-follow-up/)。
BendableView
包含三个公开属性
var damping: CGFloat // set to animate the view's edges differently than the whole view (used in an internal spring animation)
var initialSpringVelocity: CGFloat // same as above
var fillColor: UIColor // "background" color of the bendable layer
您应该在动画位置变化之前设置它们。我建议使用比调用 +animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:
时使用的值略微较低的建议值,就像这个示例一样
let bv = BendableView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
view.addSubview(bv)
// bending setup
bv.fillColor = UIColor.redColor()
bv.damping = 0.7
bv.initialSpringVelocity = 0.8
UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 0.9, initialSpringVelocity: 0.9, options: .BeginFromCurrentState | .AllowUserInteraction, animations: {
bv.frame.origin = CGPoint(x: 200, y: 300)
bv.frame.size = CGSize(width: 150, height: 150)
}, completion: nil)
祝您玩得开心!
要运行示例项目,克隆仓库,并打开 Example/AHKBendableView.xcodeproj
。
Arkadiusz Holko