【发布时间】:2016-04-07 04:26:41
【问题描述】:
我正在尝试根据 UIImageView 上的点击手势切换 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 初始化为最初不可见。
有什么明显的错误吗?
【问题讨论】:
-
语句 self.photoTitle.hidden = !self.photoTitle.hidden 在执行您的块的语句之前执行。
-
如果只是为了隐藏标签,那么你应该只使用该标签的 alpha 而不是也使用 hidden 属性,alpha 也会给你效果
-
如果您有任何理由隐藏标签,只需使用
alpha即可隐藏它。不要使用hidden。
标签: ios swift cocoa-touch