如何使用Facebook PoP ios框架水平翻转UIView?

我正在使用facebook Pop框架for iOS。 如何使视图水平翻转(在Y轴上)?

这是我的代码:

func buttonClicked(sender: UIButton) { aBoolValue = !aBoolValue sender.userInteractionEnabled = false let layer = sender.layer // First let's remove any existing animations layer.pop_removeAllAnimations() layer.removeAllAnimations() let rotation: POPSpringAnimation = POPSpringAnimation(propertyNamed:kPOPLayerRotationY) if aBoolValue == true { rotation.toValue = M_PI sender.setTitle("G", forState: UIControlState.Normal) } else { rotation.toValue = 0 sender.setTitle("P", forState: UIControlState.Normal) } rotation.completionBlock = {(anim: POPAnimation! , finished: Bool) -> Void in layer.pop_removeAllAnimations() sender.userInteractionEnabled = true } layer.pop_addAnimation(rotation, forKey: "rotation") 

结果是它按预期翻转,但在大约5-6翻转后,动画开始随机翻转而不是正常翻转。 如何以正确的方式水平翻转视图?

这是流行库中的一个错误。 请参阅https://github.com/facebook/pop/issues/71

人们可以使用UIView.animateWithDuration:方法创建一些类似的动画。

例如

 private func get3DTransformation(angle: Double) -> CATransform3D { var transform = CATransform3DIdentity transform.m34 = -1.0 / 500.0 transform = CATransform3DRotate(transform, CGFloat(angle * M_PI / 180.0), 0, 1, 0.0) return transform } private func flipAnimation(view: UIView, completion: (() -> Void) = {}) { let angle = 180.0 view.layer.transform = get3DTransformation(angle) UIView.animateWithDuration(1, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0, options: .TransitionNone, animations: { () -> Void in view.layer.transform = CATransform3DIdentity }) { (finished) -> Void in completion() } } 

 func buttonClicked(sender: UIButton) { aBoolValue = !aBoolValue if aBoolValue == true { sender.setTitle("G", forState: UIControlState.Normal) } else { sender.setTitle("P", forState: UIControlState.Normal) } flipAnimation(sender) }