[英]UIkit Dynamics in swift
Trying to convert some objective c code to swift and struggling to achieve results. 试图将一些客观的c代码转换为快速并努力实现结果。
animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
_gravity = [[UIGravityBehavior alloc] initWithItems:@[square]];
at to moment I have got 我到了那一刻
animator.referenceView = self.view
Doesn't work though. 虽然不起作用。 Can someone guide me in the right direction. 有人能引导我朝着正确的方向前进。 Thanks in advance 提前致谢
Full Code 完整代码
let square = UIView()
square.frame = CGRectMake(100, 100, 100, 100)
square.backgroundColor = UIColor.redColor()
self.view.addSubview(square)
var animator = UIDynamicAnimator()
var gravity = UIGravityBehavior()
animator.referenceView = self.view
animator.addBehavior(gravity)
holex was on to it, but the key is that you have to store a reference to the animator, here's a working example: holex正准备,但关键是你必须存储动画师的参考,这是一个工作的例子:
class ViewController: UIViewController {
var animator:UIDynamicAnimator?
override func viewDidLoad() {
super.viewDidLoad()
let square = UIView()
square.frame = CGRectMake(100, 100, 100, 100)
square.backgroundColor = UIColor.redColor()
self.view.addSubview(square)
self.animator = UIDynamicAnimator(referenceView:self.view)
var gravity = UIGravityBehavior(items: [square])
animator!.addBehavior(gravity)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.