【发布时间】:2015-11-20 18:18:06
【问题描述】:
我已经构建了一个计数器,当您向上或向下滑动时会显示动画。
所以基本上它是我动画的视图控制器内的一个圆形 UIView
当用户向上或向下滑动时增加偏移量。
它工作得很好,但现在我试图把它放在一个 .Xib 文件中,然后
在视图控制器上加载 Nib。
它不工作,只有标签开始动画,而不是
圆形视图。
如何在视图中为 xib 设置动画
这是我的代码:
````
func handleSwipes(sender:UISwipeGestureRecognizer) {
// up or down
if sender.direction == .Up {
increment = 1
offset = 10
} else {
increment = -1
offset = -10
}
// animate stuff with constraints
inc(increment)
UIView.animateWithDuration(0.18, animations: { _ in
self.labelYConstraint.constant = self.offset
self.view.layoutIfNeeded()
self.label.alpha = 1
self.label.textColor = UIColor(red: 52/255.0, green: 52/255.0, blue: 88/255.0, alpha: 1)
self.circleView.filledColor = UIColor(red: 167/255.0, green: 246/255.0, blue: 67/255.0, alpha: 1)
}
}) { _ in
UIView.animateWithDuration(0.18, animations: { _ in
self.labelYConstraint.constant = 0
self.view.layoutIfNeeded()
self.circleView.layer.backgroundColor = UIColor(red: 211/255.0, green: 211/255.0, blue: 211/255.0, alpha: 0.3).CGColor
self.label.textColor = UIColor.whiteColor()
})
}
}
````
第一个按钮是一个 UIView 动画
第二个按钮是嵌入在视图控制器中的 .Xib 文件
【问题讨论】:
-
“动画 xib”这句话完全没有意义。
-
你会如何重新提出这个问题?我知道 xib 是一种视图,我只是想明确提出问题。
-
xib 不是视图。它是一个 xib(一个 nib 文件)。
-
最好是说:如何为 xib 组件或 xib 约束设置动画?
标签: ios swift xib uiviewanimation