Skip to content
This repository was archived by the owner on Apr 19, 2023. It is now read-only.

Commit b169899

Browse files
committed
add SafeAreaInputAccessoryViewWrapperView class
1 parent 5d1bc9a commit b169899

8 files changed

Lines changed: 362 additions & 95 deletions

File tree

Example/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 262 additions & 86 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Target Support Files/Pods-SafeAreaInputAccessoryViewWrapperView_Example/Pods-SafeAreaInputAccessoryViewWrapperView_Example-frameworks.sh

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Target Support Files/Pods-SafeAreaInputAccessoryViewWrapperView_Example/Pods-SafeAreaInputAccessoryViewWrapperView_Example.debug.xcconfig

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Target Support Files/Pods-SafeAreaInputAccessoryViewWrapperView_Example/Pods-SafeAreaInputAccessoryViewWrapperView_Example.release.xcconfig

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Target Support Files/Pods-SafeAreaInputAccessoryViewWrapperView_Tests/Pods-SafeAreaInputAccessoryViewWrapperView_Tests.debug.xcconfig

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Target Support Files/Pods-SafeAreaInputAccessoryViewWrapperView_Tests/Pods-SafeAreaInputAccessoryViewWrapperView_Tests.release.xcconfig

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Target Support Files/SafeAreaInputAccessoryViewWrapperView/Info.plist

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//
2+
// SafeAreaInputAccessoryViewWrapperView.swift
3+
// StockX
4+
//
5+
// Created by Jeff Burt on 10/5/17.
6+
// Copyright © 2017 StockX. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
/**
12+
SafeAreaInputAccessoryViewWrapperView is useful for wrapping a view to be used
13+
as an inputAccessoryView. Without this, setting the view as an
14+
inputAccessoryView will ignore safe area layouts. For example, the Home screen
15+
indicator on iPhone X will battle for the same spot. This class ensures that
16+
the view respects safe area layouts and does not cover up system UI elements
17+
such as the Home screen indicator on iPhone X.
18+
*/
19+
public class SafeAreaInputAccessoryViewWrapperView: UIView {
20+
private var addedConstraints = [NSLayoutConstraint]() {
21+
didSet {
22+
NSLayoutConstraint.deactivate(oldValue)
23+
NSLayoutConstraint.activate(addedConstraints)
24+
}
25+
}
26+
27+
deinit {
28+
addedConstraints = []
29+
}
30+
31+
public init(for view: UIView) {
32+
super.init(frame: .zero)
33+
34+
addSubview(view)
35+
36+
// Allow 'self' to be sized based on autolayout constraints. Without
37+
// this, the frame would have to be set manually.
38+
autoresizingMask = .flexibleHeight
39+
40+
view.translatesAutoresizingMaskIntoConstraints = false
41+
42+
defer {
43+
let leadingAnchor: NSLayoutXAxisAnchor
44+
let trailingAnchor: NSLayoutXAxisAnchor
45+
let topAnchor: NSLayoutYAxisAnchor
46+
let bottomAnchor: NSLayoutYAxisAnchor
47+
48+
if #available(iOS 11, *) {
49+
leadingAnchor = safeAreaLayoutGuide.leadingAnchor
50+
trailingAnchor = safeAreaLayoutGuide.trailingAnchor
51+
topAnchor = safeAreaLayoutGuide.topAnchor
52+
bottomAnchor = safeAreaLayoutGuide.bottomAnchor
53+
}
54+
else {
55+
leadingAnchor = self.leadingAnchor
56+
trailingAnchor = self.trailingAnchor
57+
topAnchor = self.topAnchor
58+
bottomAnchor = self.bottomAnchor
59+
}
60+
61+
addedConstraints =
62+
[view.leadingAnchor.constraint(equalTo: leadingAnchor),
63+
view.trailingAnchor.constraint(equalTo: trailingAnchor),
64+
view.topAnchor.constraint(equalTo: topAnchor),
65+
view.bottomAnchor.constraint(equalTo: bottomAnchor)]
66+
}
67+
}
68+
69+
public required init?(coder aDecoder: NSCoder) {
70+
fatalError("init(coder:) has not been implemented")
71+
}
72+
73+
public override var intrinsicContentSize: CGSize {
74+
// Allow 'self' to be sized based on autolayout constraints. Without
75+
// this, the frame would have to be set manually.
76+
return .zero
77+
}
78+
}

0 commit comments

Comments
 (0)