forked from SwiftKickMobile/SwiftMessages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewControllerContainerView.swift
37 lines (32 loc) · 1.23 KB
/
ViewControllerContainerView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//
// ViewControllerContainerView.swift
// SwiftMessages
//
// Created by Timothy Moose on 8/14/19.
// Copyright © 2019 SwiftKick Mobile. All rights reserved.
//
import UIKit
class ViewControllerContainerView: CornerRoundingView {
weak var viewController: UIViewController? {
didSet {
updateAdditionalSafeAreaInsets()
}
}
open override func safeAreaInsetsDidChange() {
if #available(iOS 11.0, *) {
super.safeAreaInsetsDidChange()
updateAdditionalSafeAreaInsets()
}
}
/// Provides a workaround for the issue with view controller presentation,
/// where the presented view controller's view has zero `safeAreaInsets`.
/// I'm not sure if this is an iOS bug or if I'm doing something wrong (let me know!)
/// but this workaround fixes the problem by applying `additionalSafeAreaInsets`
/// to the presented view controller.
private func updateAdditionalSafeAreaInsets() {
guard let viewController = viewController else { return }
if #available(iOS 11.0, *) {
viewController.additionalSafeAreaInsets = viewController.additionalSafeAreaInsets + safeAreaInsets - viewController.view.safeAreaInsets
}
}
}