我写了一个函数来翻转视图。在动画期间,我想要隐藏一个视图并显示其他视图。
这不起作用。但是如果我在转换完成后尝试移动此视图,它会向我显示我所需的结果。
以下是我写的代码。
func tapped() {
if (showingBack) {
UIView.transitionWithView(self.contentView!, duration: 1, options: .TransitionFlipFromRight, animations: {
self.contentView?.viewWithTag(1)?.hidden = false
self.contentView?.viewWithTag(2)?.hidden = true
}, completion: { complete in
})
} else {
UIView.transitionWithView(self.contentView!, duration: 1, options: .TransitionFlipFromRight, animations: {
self.contentView?.viewWithTag(1)?.hidden = true
self.contentView?.viewWithTag(2)?.hidden = false
}, completion: { complete in
})
}
showingBack = !showingBack
}
答案 0 :(得分:2)
不幸的是,隐藏不是通过UIView动画可动画的属性。我认为你最好的选择可能是使用淡入淡出,翻转等,或者开始涉足更强大的核心动画。看一下UIView动画和核心动画的文档。
UIView.animateWithDuration(0.7, delay: 1.0, options: UIViewAnimationCurveEaseOut, animations: {
self.myView.frame = /* set the frame here */
}, completion: { finished in
println("Done!")
})
答案 1 :(得分:1)
试试这段代码......
func tapped() {
if (showingBack) {
UIView.transitionWithView(self.contentView!, duration: 1, options: .TransitionFlipFromRight, animations: {
self.contentView?.alpha = 1.0
self.Contentview2?.alpha = 0.0
}, completion: { complete in
})
} else {
UIView.transitionWithView(self.Contentview2!, duration: 1, options: .TransitionFlipFromRight, animations: {
self.contentView?.alpha = 0.0
self.Contentview2?.alpha = 1.0
}, completion: { complete in
})
}
showingBack = !showingBack
}