如何使用Facebook PoP ios框架水平翻转UIView? [英] How to flip a UIView horizontally using Facebook PoP ios framework?
本文介绍了如何使用Facebook PoP ios框架水平翻转UIView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何使视图翻转水平(在Y轴上)?
这是我的代码:
func buttonClicked(sender:UIButton){
aBoolValue =!aBoolValue
sender.userInteractionEnabled = false
let layer = sender.layer
//首先让我们删除任何现有的动画
layer.pop_removeAllAnimations()
layer.removeAllAnimations()
let rotation:POPSpringAnimation = POPSpringAnimation(propertyNamed:kPOPLayerRotationY)
如果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) - >空的
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,动画:{() - > Void in
view.layer.transform = CATransform3DIdentity
}){(已完成) - >无效
完成()
}
}
func buttonClicked(sender:UIButton){
aBoolValue =!aBoolValue
如果aBoolValue == true {
sender.setTitle(G,forState:UIControlState.Normal)
} else {
sender.setTitle(P,forState:UIControlState.Normal)
}
flipAnimation(发件人)
}
I am using facebook Pop framework for iOS. How do i make a view flip horizontal (on its Y axis) ?
Here is my code:
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")
The results of this is that it flips as expected, but after about 5-6 flips, the animation begins to flip randomly and not normally. How do i flip a view horizontally the right way?
解决方案
It is a bug in pop library. see https://github.com/facebook/pop/issues/71
People can create somewhat similar animation with UIView.animateWithDuration:
method.
for example
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)
}
这篇关于如何使用Facebook PoP ios框架水平翻转UIView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文