728x90
CAEmitterLayer로 애니메이션 효과 만들기
import UIKit
class ViewController: UIViewController {
let emitter = CAEmitterLayer()
override func viewDidLoad() {
super.viewDidLoad()
createEmitter()
}
private func createEmitter() {
emitter.emitterPosition = CGPoint(x: view.center.x, y: view.center.y)
let cell = CAEmitterCell()
cell.scale = 0.01
cell.lifetime = 2
cell.birthRate = 10
cell.velocity = 100
cell.emissionRange = .pi * (2/3)
cell.color = UIColor.red.cgColor
cell.contents = UIImage(named: "dot")!.cgImage
emitter.emitterCells = [cell]
view.layer.addSublayer(emitter)
}
override func viewDidAppear(_ animated: Bool) {
DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: { [weak self] in
guard let strongSelf = self else {return}
strongSelf.emitter.removeFromSuperlayer()
})
}
}
728x90
'iOS > 설명' 카테고리의 다른 글
[iOS] NSClassFromString (0) | 2021.07.05 |
---|---|
[iOS] translatesAutoresizingMaskIntoConstraints (0) | 2021.06.17 |
[iOS] UIWindow (0) | 2021.06.03 |
[iOS] iOS 앱 배포 방식 (2) | 2021.05.27 |
[iOS] UIView initializer (0) | 2021.05.27 |
댓글