V2SuperUser 最近的时间轴更新
V2SuperUser

V2SuperUser

V2EX 第 465019 号会员,加入于 2020-01-14 15:39:25 +08:00
V2SuperUser 最近回复了
6 天前
回复了 DreamCMS 创建的主题 iDev swift5 如何实现这样的布局,求高手指点一下
```swift
import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

let screenBounds = UIScreen.main.bounds

let imageView = UIImageView(image: UIImage(named: "24110307_5"))
view.addSubview(imageView)
let imageW = screenBounds.width + 100
imageView.frame = CGRect(x: 0, y: 0, width: imageW, height: screenBounds.height)


//方式 1
// UIView.animate(withDuration: 4) {
// imageView.frame = CGRect(x: -100, y: 0, width: imageW, height: screenBounds.height)
// } completion: { isFinished in
// if isFinished{
// print("结束")
// }
// }

//方式 2:
let animation = CABasicAnimation()
animation.keyPath = "transform.translation.x"
animation.fromValue = 0
animation.toValue = -100
animation.duration = 4
animation.isRemovedOnCompletion = false
animation.fillMode = .forwards
imageView.layer.removeAllAnimations()
imageView.layer.add(animation, forKey: nil)

}

}
```
蒲公英必须支持一下
关于   ·   帮助文档   ·   API   ·   FAQ   ·   我们的愿景   ·   广告投放   ·   感谢   ·   实用小工具   ·   2823 人在线   最高记录 5497   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 18ms · UTC 14:00 · PVG 22:00 · LAX 07:00 · JFK 10:00
Developed with CodeLauncher
♥ Do have faith in what you're doing.