use*_*509 3 animation uiview ios animatewithduration swift
目的:
如何制作我UIView想要扩展以填满整个屏幕的动画。需要UIView在动画时以平滑、均匀和平衡的方式扩展。
我在屏幕上放置了一个红色方块,一开始很小,然后扩展到适合屏幕。(图 1。)
let subview = UIView()
subview.backgroundColor = .red
subview.frame = CGRect(x: 60, y: 200, width: 50, height: 50)
self.view.addSubview(subview)
Run Code Online (Sandbox Code Playgroud)
问题:
在 Swift 2 和 Swift 3 中,使用
animateWithDuration,如何使红色方块UIView以平衡且均匀的方式向各个方向扩展以填充整个屏幕?Run Code Online (Sandbox Code Playgroud)UIView.animateWithDuration(1.0, delay: 0, options: nil, animations: { ????? }, completion: nil)
图片1:
你可以试试这个,我将持续时间设置为 5 秒,但你明白了。
let viewWidth = view.frame.width
let viewHeight = view.frame.height
UIView.animate(withDuration: 5) {
subview.frame = CGRect(x: 0, y: 0, width: viewWidth, height: viewHeight)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13671 次 |
| 最近记录: |