Skip to content

Commit b8d461b

Browse files
committed
Small tweaks
1 parent c6054ac commit b8d461b

File tree

3 files changed

+14
-23
lines changed

3 files changed

+14
-23
lines changed

demo/Sources/AboutViewController/AboutViewController.swift

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ class AboutViewController: UIViewController {
3131
.applyingFilter(CIFilter.bumpDistortion()) {
3232
$0.center = center
3333
$0.radius = 300
34-
$0.scale = Float(1 + cos(CACurrentMediaTime())) / 5
34+
$0.scale = 0.2
3535
}
3636
}
3737

3838
@IBAction private func panGestureRecognized(_ gesture: UIPanGestureRecognizer) {
3939
if gesture.state == .began {
40-
snapshotImage = CIImage(image: view.snapshot())
40+
snapshotImage = view.snapshot()
4141
mtkView.isPaused = false
4242
mtkView.isHidden = false
4343
}
@@ -61,16 +61,10 @@ class AboutViewController: UIViewController {
6161

6262
@IBOutlet var mtkView: MTKView!
6363

64-
private lazy var device = MTLCreateSystemDefaultDevice()!
64+
private let context = CIContext()
65+
private let device = MTLCreateSystemDefaultDevice()!
6566
private lazy var commandQueue = device.makeCommandQueue()!
6667

67-
private lazy var context = CIContext(
68-
mtlCommandQueue: commandQueue,
69-
options: [
70-
.cacheIntermediates: false,
71-
]
72-
)
73-
7468
override func viewDidLoad() {
7569
super.viewDidLoad()
7670
mtkView.device = device

demo/Sources/OnboardingViewController/OnboardingViewController.swift

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class OnboardingViewController: UIViewController {
4444
return backgroundSourceSnapshot
4545
.applyingFilter(CIFilter.barsSwipeTransition()) {
4646
$0.targetImage = backgroundTargetSnapshot
47-
$0.angle = .pi / 4
47+
$0.angle = 9 * .pi / 5
4848
$0.width = 150
4949
$0.time = Float(progress)
5050
}
@@ -55,9 +55,9 @@ class OnboardingViewController: UIViewController {
5555
currentImage = (currentImage + 1) % onboardingImageNames.count
5656
let targetImageName = onboardingImageNames[currentImage]
5757

58-
backgroundSourceSnapshot = CIImage(image: backgroundView.snapshot())
58+
backgroundSourceSnapshot = backgroundView.snapshot()
5959
backgroundView.image = UIImage(named: targetImageName)
60-
backgroundTargetSnapshot = CIImage(image: backgroundView.snapshot())
60+
backgroundTargetSnapshot = backgroundView.snapshot()
6161

6262
startTime = CACurrentMediaTime()
6363
mtkView.isHidden = false
@@ -76,16 +76,10 @@ class OnboardingViewController: UIViewController {
7676

7777
@IBOutlet var mtkView: MTKView!
7878

79-
private lazy var device = MTLCreateSystemDefaultDevice()!
79+
private let context = CIContext()
80+
private let device = MTLCreateSystemDefaultDevice()!
8081
private lazy var commandQueue = device.makeCommandQueue()!
8182

82-
private lazy var context = CIContext(
83-
mtlCommandQueue: commandQueue,
84-
options: [
85-
.cacheIntermediates: false,
86-
]
87-
)
88-
8983
override func viewDidLoad() {
9084
super.viewDidLoad()
9185
mtkView.device = device

demo/Sources/UIView+Snapshot.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
// Created by Florian Denis on 04/01/2023.
66
//
77

8+
import CoreImage
89
import UIKit
910

1011
extension UIView {
11-
public func snapshot() -> UIImage {
12+
public func snapshot() -> CIImage? {
1213
let renderer = UIGraphicsImageRenderer(size: bounds.size)
13-
return renderer.image { _ in drawHierarchy(in: bounds, afterScreenUpdates: true) }
14+
return CIImage(image: renderer.image { _ in
15+
drawHierarchy(in: bounds, afterScreenUpdates: true)
16+
})
1417
}
1518
}
1619

0 commit comments

Comments
 (0)