如何同时使用不同的动画曲线为AutoLayout约束设置动画?
例如,使用线性曲线为widthAnchor
和heightAnchor
设置动画,但使用弹簧动画设置动画centerXAnchor
和centerYAnchor
(在同一视图上)。 两种动画都需要同时执行。
我所知道的是如何一次动画每个人(在view.layoutIfNeeded()
内调用UIView.animate
),但如何分别为它们制作动画?
答案 0 :(得分:0)
你必须执行如下操作: -
@SpringBootApplication
public class H2Application {
public static void main(String[] args) {
SpringApplication.run(H2Application.class, args);
}
@Bean
CommandLineRunner init (StudentRepo studentRepo){
return args -> {
List<String> names = Arrays.asList("udara", "sampath");
names.forEach(name -> studentRepo.save(new Student(name)));
};
}
}
如果你想添加一些动画选项,请使用下面的代码: -
UIView.animate(withDuration: 0.2, animations: {
//perform animation of height
}, completion: { _ in
UIView.animate(withDuration: 0.2, animations: {
//perform animation of width
}, completion: nil)
})
两者在一起: -
UIView.animateWithDuration(0.2, delay: 0.2, options: UIViewAnimationOptions."Set your Animationoption", animations: {
//perform animation of height
}, completion: { _ in
UIView.animateWithDuration(0.2, delay: 0.2, options: UIViewAnimationOptions."Set your Animationoption", animations: {
//perform animation of width
}, completion: nil)
})
谢谢。
答案 1 :(得分:0)
您应该尝试创建CABasicAnimation
并将fromValue
设置为每个视图的当前值,然后在没有动画块的情况下调用layoutIfNeeded()
。后者将更改视图的框架。如果您在布局步骤之后添加动画,则应该对修改进行动画处理。
这可能看起来像这样
let animation1 = CABasicAnimation()
let animation2 = CABasicAnimation()
animation1.fromValue = view1.center
animation1... // Set further properties to configure the animation
animation2.fromValue = ... // Same with second view
// and so on
self.view.layoutIfNeeded()
view1.layer.add(animation1, forKey: "center")
view2.layer.add(animation2, forKey: ...)
我还没有尝试过,但是很高兴听到它是否有效。