gpt4 book ai didi

ios - 如何在 View Controller 内为 xib 约束设置动画?

转载 作者:行者123 更新时间:2023-11-29 01:27:40 25 4
gpt4 key购买 nike

我构建了一个计数器,当您向上或向下滑动时它会显示动画。

所以基本上它是我制作动画的 View Controller 内的一个 Circular UIView

通过在用户向上或向下滑动时增加偏移量。

它工作得很好,但现在我想把它放在一个 .Xib 文件中,然后

在 View Controller 上加载 Nib。

而且它不起作用,只有标签正在动画但不是

圆形 View 。

如何在 View 中设置 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 动画

第二个按钮是嵌入在 View Controller 中的.Xib 文件

enter image description here

最佳答案

您似乎在为标签的 Y 约束设置动画。您必须确保为设置整个组位置的约束设置动画。

一个简单的方法是,在 xib 中,创建一个透明的 subview 并将所有元素放入其中,并创建一个 Y 约束以将该 subview 定位在主 xib View 中。当您为新约束设置动画时,它应该将所有元素移动到一起。

如果这有帮助,请告诉我。

关于ios - 如何在 View Controller 内为 xib 约束设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33833446/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com