有没有一种方法可以设置以下内容的动画:
UIView *exampleView = //something
[exampleView.superview bringToFront:exampleView];
在for循环中,因此视图层次结构中的每个视图都会一次一个地放到层次结构的前面,每次视图更改之间都会有延迟,因为当我将上述代码行放入for循环中的动画中时,所有视图都会立即放到层次结构的前面,因为动画在代码中立即发生,并且只会随着时间的推移而改变它们在屏幕上的显示方式。
发布于 2014-01-20 12:01:36
只能为可设置动画的属性的更改设置动画。您不能为任意方法的制定设置动画效果。并且只有某些属性是可动画的(它们被明确地列为动画)。属性是可设置动画的,因为有某种方法可以直观地表示初始值和最终值之间的中间阶段。
您可能会调查图层的zPosition
属性,明确地说它是可动画的,但我不知道视觉效果是什么样子的。
发布于 2020-04-27 11:20:07
您还可以使用UIView的transition(from:to:duration:options:completion:)
或transition(with:duration:options:animations:completion:)
函数设置过渡的动画效果。指向这些函数的苹果文档的链接是here和here。
请记住,苹果从iOS 13开始不鼓励使用这些动画技术,并建议使用UIViewPropertyAnimator
类函数。
让我举一个在Swift中使用的例子:
let containerView = UIView()
let transitionFromView = UIView()
containerView.addSubview(transitionFromView)
//add your layout constraints to the transitionFromView within the containerView
let transitionToView = UIView()
containerView.addSubview(transitionToView)
//add your layout constraints to the transitionToView within the containerView
...
func performTransition1() {
//since both transitionFromView and transitionToView have already been added
//to their parent's subviews, we can use showHideTransitionViews animation option
//in this example I am using transitionCrossDissolve animation; however,
//there are other options that can be used instead such as
//transitionFlipFromRight
UIView.transition(from: transitionFromView,
to: transitionToView,
duration: 0.5,
options: [.showHideTransitionViews, .transitionCrossDissolve],
completion: nil)
}
ps:动画选项的完整列表可以在here中找到
https://stackoverflow.com/questions/21225974
复制相似问题