Skip to content

Commit bbb02f0

Browse files
committed
Improve message view animation
1 parent 806484e commit bbb02f0

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

Sources/Controllers/MessageViewController.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public enum MessageStyle {
88

99
public final class MessageViewController: UIViewController {
1010
// Blur effect view.
11-
private lazy var blurView: BlurView = .init()
11+
private lazy var blurView: UIVisualEffectView = .init(effect: UIBlurEffect(style: .extraLight))
1212
/// Text label.
1313
public private(set) lazy var textLabel: UILabel = .init()
1414
/// Info image view.
@@ -30,7 +30,7 @@ public final class MessageViewController: UIViewController {
3030
public override func viewDidLoad() {
3131
super.viewDidLoad()
3232
view.addSubview(blurView)
33-
blurView.addSubviews(textLabel, imageView, borderView)
33+
blurView.contentView.addSubviews(textLabel, imageView, borderView)
3434
setupSubviews()
3535
handleStateUpdate()
3636
}
@@ -123,7 +123,7 @@ public final class MessageViewController: UIViewController {
123123
delay: 0.5,
124124
options: [.beginFromCurrentState],
125125
animations: ({ [weak self] in
126-
self?.blurView.effectView.effect = UIBlurEffect(style: blurStyle)
126+
self?.blurView.effect = UIBlurEffect(style: blurStyle)
127127
}),
128128
completion: ({ [weak self] _ in
129129
self?.animate(blurStyle: blurStyle == .light ? .extraLight : .light)
@@ -181,11 +181,11 @@ extension MessageViewController {
181181
private func makeCollapsedConstraints() -> [NSLayoutConstraint] {
182182
let padding: CGFloat = 10
183183
var constraints = [
184-
imageView.centerYAnchor.constraint(equalTo: blurView.centerYAnchor),
184+
imageView.topAnchor.constraint(equalTo: blurView.topAnchor, constant: 18),
185185
imageView.widthAnchor.constraint(equalToConstant: 30),
186186
imageView.heightAnchor.constraint(equalToConstant: 27),
187187

188-
textLabel.topAnchor.constraint(equalTo: imageView.topAnchor),
188+
textLabel.topAnchor.constraint(equalTo: imageView.topAnchor, constant: -3),
189189
textLabel.leadingAnchor.constraint(equalTo: imageView.trailingAnchor, constant: 10)
190190
]
191191

Sources/Controllers/ScannerViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,11 @@ open class ScannerController: UIViewController {
107107
resetState()
108108
}
109109

110+
self.messageViewController.state = self.status.state
110111
UIView.animate(withDuration: duration,
111112
animations: {
113+
self.infoView.layoutIfNeeded()
112114
self.infoView.frame = self.infoFrame
113-
self.messageViewController.state = self.status.state
114115
},
115116
completion: { [weak self] _ in
116117
if delayReset {
@@ -217,8 +218,6 @@ open class ScannerController: UIViewController {
217218
open override func viewDidAppear(_ animated: Bool) {
218219
super.viewDidAppear(animated)
219220
animateFocusView()
220-
221-
status = Status(state: .scanning)
222221
}
223222

224223
open override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
@@ -487,6 +486,7 @@ extension ScannerController: AVCaptureMetadataOutputObjectsDelegate {
487486

488487
extension ScannerController: HeaderViewControllerDelegate {
489488
public func headerViewControllerDidTapCloseButton(_ controller: HeaderViewController) {
489+
status = Status(state: .scanning)
490490
dismissalDelegate?.scannerDidDismiss(self)
491491
}
492492
}

Sources/Extensions/UIViewController+Extensions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ extension UIViewController {
1717

1818
private func layout(childViewController: UIViewController) {
1919
let childView = childViewController.view
20-
childView?.translatesAutoresizingMaskIntoConstraints = true
21-
childView?.autoresizingMask = [.flexibleWidth, .flexibleHeight]
20+
//childView?.translatesAutoresizingMaskIntoConstraints = true
21+
//childView?.autoresizingMask = [.flexibleWidth, .flexibleHeight]
2222
childView?.frame = view.bounds
2323
}
2424
}

0 commit comments

Comments
 (0)