我试图根据UIImageView上的Tap Gesture切换UILabel的可见性。执行切换的代码如下:
func imageTapped(img: UIImageView) {
print(photoTitle.hidden)
if (photoTitle.hidden) {
UIView.animateWithDuration(0.5, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
self.photoTitle.alpha = 1
}, completion: nil)
}
else {
UIView.animateWithDuration(0.5, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
self.photoTitle.alpha = 0
}, completion: nil)
}
self.photoTitle.hidden = !self.photoTitle.hidden
}
这个问题是它似乎忽略了第二次点击时的动画,即再次隐藏UILabel。它变得不可见而不是逐渐动画。在viewdDidLoad()中,我将photoTitle.hidden = true初始化为最初不可见。
任何明显的错误?
答案 0 :(得分:0)
您需要将self.photoTitle.hidden = true
移至其他条件的完成块
答案 1 :(得分:0)
尝试更改此功能
func imageTapped(img: UIImageView) {
print(photoTitle.hidden)
UIView.animateWithDuration(0.5, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
self.photoTitle.alpha = self.photoTitle.alpha < 0.5 ? 1.0 : 0.0
}, completion: nil)
}
答案 2 :(得分:0)
hidden
无法处理此动画,您可以代替alpha