【发布时间】:2018-07-06 15:44:25
【问题描述】:
我只是想在一些 uiviews 中设置动画,
- 首先我将
viewWillAppear中的子视图移出屏幕边界 - 然后我在
viewDidAppear中使用UIView.animate将它们移回原位
`
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
label.center.x -= view.bounds.width
username.center.x -= view.bounds.width
password.center.x -= view.bounds.width
login.center.x -= view.bounds.width
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
print("view did appear")
UIView.animate(withDuration: 1) {
self.label.center.x += self.view.bounds.width
self.username.center.x += self.view.bounds.width
self.password.center.x += self.view.bounds.width
self.login.center.x += self.view.bounds.width
}
}
我做错了什么?
编辑 1
当我评论viewDidAppear 时,它对视图没有任何影响。 (它们在情节提要中就位)
【问题讨论】:
-
你做得很好,继续努力。但问题是什么?
-
当您说“应用程序启动时”是指您尝试在启动屏幕中执行此操作吗?
-
@dahiya_boy 它不起作用,实际上当我评论
viewDidAppear时,视图根本不动。 -
@Fogmeister 不,我的意思是应用程序启动时它们不存在,然后超过 1 秒,它们从侧面进入动画。
-
您是否使用自动布局约束来设置它们在情节提要中的位置?如果是这样,您需要为约束值设置动画,否则自动布局会将它们保持在原位。
标签: ios swift uiview core-animation uiviewanimation