我只是在测试一些“下落” View 的动画。我想模拟从天上掉下来的叶子。我编写了这个非常简单的代码,尚未完成,但用于检查我是否做得正确。
但是,“下降” View 是否应该附加自动布局
约束?当 View 的其余部分通过自动布局完成时,像这样将 View 添加到屏幕上是不是很糟糕? 我正在使用 Swift 2
和 iOS 9
。
let rectangleView = UIView(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
rectangleView.backgroundColor = UIColor.redColor()
backgroundView.addSubview(rectangleView)
UIView.animateWithDuration(10, delay: 0, options: [UIViewAnimationOptions.CurveEaseIn], animations: {
rectangleView.center = CGPoint(x: rectangleView.center.x, y: 300)
}, completion: nil)
最佳答案
如果您的 View 在屏幕上自由移动,那么我认为没有任何理由使用自动布局约束。
将 subview 添加到使用自动布局的 UI 并自行设置动画是没有问题的,就像您所做的那样。并非屏幕上的所有内容都必须通过自动布局进行管理。
关于ios - 在 UIView 上模拟 "falling"对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34210877/