From a8eda2b1d060f63d0237c77aa78b3b3fe164d14a Mon Sep 17 00:00:00 2001 From: baegteun Date: Mon, 31 Jan 2022 00:28:00 +0900 Subject: [PATCH 1/8] Create keyboardLayout --- .../package.xcworkspace/contents.xcworkspacedata | 7 +++++++ Example/.DS_Store | Bin 0 -> 6148 bytes Sources/PinLayout.swift | 6 ++++++ 3 files changed, 13 insertions(+) create mode 100644 .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata create mode 100644 Example/.DS_Store diff --git a/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..919434a6 --- /dev/null +++ b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Example/.DS_Store b/Example/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..29adcda8a34bb94800ec12dd3a0708aa663a0e11 GIT binary patch literal 6148 zcmeHK%Syvg5Is}7h`8xe7ec92=Dzy*WJDc%!T$}-Cz!^9=2H3Mzl9PyTodIXS8Q3tO--nc{m>G5v z!>5BLi~vOajSNCxX9>+o4Ku?oBJWTnrV?YS*oYx9o$IN^WrkhEm=3YwL+r_76N-eV zvwj-FAz4JX&VVzp%fL~*9BKc*`g#7}P4X*ez!^9w24t8Q`IK9--rC!o_S%#>qpE0J m7jct9C$wV5YAZga2H|?D4ly(AB65Y|KLUXUH_pJHGVle%N=b { return .zero } } + + public var keyBoardLayout: PEdgeInsets { + guard #available(iOS 15.0, *) else { return .zero } + guard let view = view as? UIView else { return .zero } + return view.keyboardLayoutGuide + } public var readableMargins: PEdgeInsets { guard #available(iOS 9.0, *) else { return .zero } From 6db3cc14c6b1bfe76ff44fc8a4b73cc0f531d481 Mon Sep 17 00:00:00 2001 From: baegteun Date: Tue, 1 Feb 2022 00:26:22 +0900 Subject: [PATCH 2/8] :memo: :: pin.keyBoardLayout --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 25c95bb3..a16f5e4c 100644 --- a/README.md +++ b/README.md @@ -1229,6 +1229,7 @@ PinLayout expose them using these properties: 1. **`UIView.pin.safeArea`**: Expose UIKit `UIView.safeAreaInsets` / `UIView.safeAreaLayoutGuide`. 2. **`UIView.pin.readableMargins`**: Expose UIKit `UIView.readableContentGuide`. 3. **`UIView.pin.layoutMargins`**: Expose UIKit `UIView.layoutMargins` / `UIView.layoutMarginsGuide`. +4. **`UIView.pin.keyBoardLayout`**: Expose UIKit `UIView.keyboardLayoutGuide`. The following image display the 3 areas on an iPad in landscape mode. @@ -1360,6 +1361,20 @@ PinLayout's `UIView.pin.layoutMargins` property expose directly the value of UIK
+### 4. pin.keyBoardLayout: + +##### Property: +* **`pin.keyBoardLayout: UIEdgeInset`** +PinLayout's `UIView.pin.keyBoardLayout` property expose directly the value of UIKit [`UIView.keyboardLayoutGuide`](https://developer.apple.com/documentation/uikit/keyboards_and_input/adjusting_your_layout_with_keyboard_layout_guide). This is really useful when layout adjustment due to the keyboard is required. + + Bottom of safe area when the keyboard undocked + +##### Usage example: +```swift + view.pin.bottom(pin.keyBoardLayout.top) +``` + + ## WrapContent @@ -1624,7 +1639,7 @@ PinLayout can display warnings in the console when pin rules cannot be applied o * The newly pinned attributes conflict with other already pinned attributes. Example: `view.pin.left(10).right(10).width(200)` -👉 Layout Conflict: `width(200) won't be applied since it conflicts with the following already set properties: left: 0, right: 10.`
 +👉 Layout Conflict: `width(200) won't be applied since it conflicts with the following already set properties: left: 0, right: 10.` * The newly pinned attributes have already been set to another value. Example: From 8dbf46b5140978ea4aea7309138be13ae6a3a9af Mon Sep 17 00:00:00 2001 From: baegteun Date: Tue, 1 Feb 2022 00:30:44 +0900 Subject: [PATCH 3/8] :sparkles: :: pin.keyBoardLayout not support tvOS --- README.md | 2 ++ Sources/PinLayout.swift | 16 ++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a16f5e4c..5ae056ea 100644 --- a/README.md +++ b/README.md @@ -1369,6 +1369,8 @@ PinLayout's `UIView.pin.keyBoardLayout` property expose directly the value of UI Bottom of safe area when the keyboard undocked + This property can be used from iOS 15 and above. + ##### Usage example: ```swift view.pin.bottom(pin.keyBoardLayout.top) diff --git a/Sources/PinLayout.swift b/Sources/PinLayout.swift index f2fa5c2c..d17305b6 100644 --- a/Sources/PinLayout.swift +++ b/Sources/PinLayout.swift @@ -83,6 +83,16 @@ public class PinLayout { } apply() } + + #if os(iOS) + + public var keyBoardLayout: PEdgeInsets { + guard #available(iOS 15.0, *) else { return .zero } + guard let view = view as? UIView else { return .zero } + return view.keyboardLayoutGuide + } + + #endif #if os(iOS) || os(tvOS) public var safeArea: PEdgeInsets { @@ -97,12 +107,6 @@ public class PinLayout { } } - public var keyBoardLayout: PEdgeInsets { - guard #available(iOS 15.0, *) else { return .zero } - guard let view = view as? UIView else { return .zero } - return view.keyboardLayoutGuide - } - public var readableMargins: PEdgeInsets { guard #available(iOS 9.0, *) else { return .zero } guard let view = view as? UIView else { return .zero } From 0d4cbbe5a6fe4aa3e39c5ddefe88f58d33b9b066 Mon Sep 17 00:00:00 2001 From: baegteun Date: Tue, 1 Feb 2022 00:31:09 +0900 Subject: [PATCH 4/8] :art: :: lint --- Sources/PinLayout.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/Sources/PinLayout.swift b/Sources/PinLayout.swift index d17305b6..ac9b9a41 100644 --- a/Sources/PinLayout.swift +++ b/Sources/PinLayout.swift @@ -85,13 +85,11 @@ public class PinLayout { } #if os(iOS) - public var keyBoardLayout: PEdgeInsets { guard #available(iOS 15.0, *) else { return .zero } guard let view = view as? UIView else { return .zero } return view.keyboardLayoutGuide } - #endif #if os(iOS) || os(tvOS) From 80da6d2d5dc6f8ad40d2cb8a71184562f05a1e65 Mon Sep 17 00:00:00 2001 From: baegteun Date: Tue, 1 Feb 2022 00:38:50 +0900 Subject: [PATCH 5/8] :recycle: :: keyBoardLayout -> keyboardLayout --- README.md | 18 +++++++++--------- Sources/PinLayout.swift | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5ae056ea..368451e6 100644 --- a/README.md +++ b/README.md @@ -1221,17 +1221,17 @@ This example layout an UIImageView at the top and center it horizontally, it als -## safeArea, readable and layout margins +## safeArea, keyboardLayout, readable and layout margins -UIKit expose 3 kind of areas/guides that can be used to layout views. +UIKit expose 4 kind of areas/guides that can be used to layout views. PinLayout expose them using these properties: 1. **`UIView.pin.safeArea`**: Expose UIKit `UIView.safeAreaInsets` / `UIView.safeAreaLayoutGuide`. 2. **`UIView.pin.readableMargins`**: Expose UIKit `UIView.readableContentGuide`. 3. **`UIView.pin.layoutMargins`**: Expose UIKit `UIView.layoutMargins` / `UIView.layoutMarginsGuide`. -4. **`UIView.pin.keyBoardLayout`**: Expose UIKit `UIView.keyboardLayoutGuide`. +4. **`UIView.pin.keyboardLayout`**: Expose UIKit `UIView.keyboardLayoutGuide`. -The following image display the 3 areas on an iPad in landscape mode. +The following image display the 3 areas on an iPad in landscape mode. (safeArea, readableMargins, layoutMargins) @@ -1361,19 +1361,19 @@ PinLayout's `UIView.pin.layoutMargins` property expose directly the value of UIK
-### 4. pin.keyBoardLayout: +### 4. pin.keyboardLayout: ##### Property: -* **`pin.keyBoardLayout: UIEdgeInset`** -PinLayout's `UIView.pin.keyBoardLayout` property expose directly the value of UIKit [`UIView.keyboardLayoutGuide`](https://developer.apple.com/documentation/uikit/keyboards_and_input/adjusting_your_layout_with_keyboard_layout_guide). This is really useful when layout adjustment due to the keyboard is required. +* **`pin.keyboardLayout: UIEdgeInset`** +PinLayout's `UIView.pin.keyboardLayout` property expose directly the value of UIKit [`UIView.keyboardLayoutGuide`](https://developer.apple.com/documentation/uikit/keyboards_and_input/adjusting_your_layout_with_keyboard_layout_guide). This is really useful when layout adjustment due to the keyboard is required. - Bottom of safe area when the keyboard undocked + Bottom of safe area when the keyboard undocked. This property can be used from iOS 15 and above. ##### Usage example: ```swift - view.pin.bottom(pin.keyBoardLayout.top) + container.pin.bottom(view.pin.keyboardLayout.top) ``` diff --git a/Sources/PinLayout.swift b/Sources/PinLayout.swift index ac9b9a41..db9def1c 100644 --- a/Sources/PinLayout.swift +++ b/Sources/PinLayout.swift @@ -85,7 +85,7 @@ public class PinLayout { } #if os(iOS) - public var keyBoardLayout: PEdgeInsets { + public var keyboardLayout: PEdgeInsets { guard #available(iOS 15.0, *) else { return .zero } guard let view = view as? UIView else { return .zero } return view.keyboardLayoutGuide From 1a3b54c8e0bf6d9e730faa220e4296f8385abfdd Mon Sep 17 00:00:00 2001 From: baegteun Date: Tue, 1 Feb 2022 00:55:19 +0900 Subject: [PATCH 6/8] :recycle: :: keyboardLayout -> keyboardMargins --- README.md | 12 ++++++------ Sources/PinLayout.swift | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 368451e6..54647595 100644 --- a/README.md +++ b/README.md @@ -1221,7 +1221,7 @@ This example layout an UIImageView at the top and center it horizontally, it als -## safeArea, keyboardLayout, readable and layout margins +## safeArea, keyboardMargins, readable and layout margins UIKit expose 4 kind of areas/guides that can be used to layout views. PinLayout expose them using these properties: @@ -1229,7 +1229,7 @@ PinLayout expose them using these properties: 1. **`UIView.pin.safeArea`**: Expose UIKit `UIView.safeAreaInsets` / `UIView.safeAreaLayoutGuide`. 2. **`UIView.pin.readableMargins`**: Expose UIKit `UIView.readableContentGuide`. 3. **`UIView.pin.layoutMargins`**: Expose UIKit `UIView.layoutMargins` / `UIView.layoutMarginsGuide`. -4. **`UIView.pin.keyboardLayout`**: Expose UIKit `UIView.keyboardLayoutGuide`. +4. **`UIView.pin.keyboardMargins`**: Expose UIKit `UIView.keyboardLayoutGuide`. The following image display the 3 areas on an iPad in landscape mode. (safeArea, readableMargins, layoutMargins) @@ -1361,11 +1361,11 @@ PinLayout's `UIView.pin.layoutMargins` property expose directly the value of UIK
-### 4. pin.keyboardLayout: +### 4. pin.keyboardMargins: ##### Property: -* **`pin.keyboardLayout: UIEdgeInset`** -PinLayout's `UIView.pin.keyboardLayout` property expose directly the value of UIKit [`UIView.keyboardLayoutGuide`](https://developer.apple.com/documentation/uikit/keyboards_and_input/adjusting_your_layout_with_keyboard_layout_guide). This is really useful when layout adjustment due to the keyboard is required. +* **`pin.keyboardMargins: UIEdgeInset`** +PinLayout's `UIView.pin.keyboardMargins` property expose directly the value of UIKit [`UIView.keyboardLayoutGuide`](https://developer.apple.com/documentation/uikit/keyboards_and_input/adjusting_your_layout_with_keyboard_layout_guide). This is really useful when layout adjustment due to the keyboard is required. Bottom of safe area when the keyboard undocked. @@ -1373,7 +1373,7 @@ PinLayout's `UIView.pin.keyboardLayout` property expose directly the value of UI ##### Usage example: ```swift - container.pin.bottom(view.pin.keyboardLayout.top) + container.pin.bottom(view.pin.keyboardMargins.top) ``` diff --git a/Sources/PinLayout.swift b/Sources/PinLayout.swift index db9def1c..777182d1 100644 --- a/Sources/PinLayout.swift +++ b/Sources/PinLayout.swift @@ -85,7 +85,7 @@ public class PinLayout { } #if os(iOS) - public var keyboardLayout: PEdgeInsets { + public var keyboardMargins: PEdgeInsets { guard #available(iOS 15.0, *) else { return .zero } guard let view = view as? UIView else { return .zero } return view.keyboardLayoutGuide From bb575b07cb1726faafd095a98c9258fdf378f7ea Mon Sep 17 00:00:00 2001 From: baegteun Date: Tue, 1 Feb 2022 02:27:03 +0900 Subject: [PATCH 7/8] :bug: :: keyboardMargins return UIEdgeInsets --- Example/.DS_Store | Bin 6148 -> 6148 bytes Sources/PinLayout.swift | 9 ++++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Example/.DS_Store b/Example/.DS_Store index 29adcda8a34bb94800ec12dd3a0708aa663a0e11..b066f01559af21ba010ba62c5489cda58c04ed25 100644 GIT binary patch delta 19 acmZoMXffCjz{F&tI(ZJ0#pW)iDp3GEvIYGB delta 19 acmZoMXffCjz{I3CZSou@i_Kk3RiXev+6HI< diff --git a/Sources/PinLayout.swift b/Sources/PinLayout.swift index 777182d1..c2b5ef9e 100644 --- a/Sources/PinLayout.swift +++ b/Sources/PinLayout.swift @@ -88,7 +88,14 @@ public class PinLayout { public var keyboardMargins: PEdgeInsets { guard #available(iOS 15.0, *) else { return .zero } guard let view = view as? UIView else { return .zero } - return view.keyboardLayoutGuide + + let layoutFrame = view.keyboardLayoutGuide.layoutFrame + guard !layoutFrame.isEmpty else { return .zero } + + return UIEdgeInsets(top: layoutFrame.origin.y, + left: layoutFrame.origin.x, + bottom: view.frame.height - layoutFrame.origin.y - layoutFrame.height, + right: view.frame.width - layoutFrame.origin.x - layoutFrame.width) } #endif From e87f0442c5d570cf5223c160029c009d0c34d92c Mon Sep 17 00:00:00 2001 From: baegteun Date: Tue, 1 Feb 2022 12:42:18 +0900 Subject: [PATCH 8/8] :recycle: :: keyboardMargins block --- Sources/PinLayout.swift | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Sources/PinLayout.swift b/Sources/PinLayout.swift index c2b5ef9e..e614b16e 100644 --- a/Sources/PinLayout.swift +++ b/Sources/PinLayout.swift @@ -83,21 +83,6 @@ public class PinLayout { } apply() } - - #if os(iOS) - public var keyboardMargins: PEdgeInsets { - guard #available(iOS 15.0, *) else { return .zero } - guard let view = view as? UIView else { return .zero } - - let layoutFrame = view.keyboardLayoutGuide.layoutFrame - guard !layoutFrame.isEmpty else { return .zero } - - return UIEdgeInsets(top: layoutFrame.origin.y, - left: layoutFrame.origin.x, - bottom: view.frame.height - layoutFrame.origin.y - layoutFrame.height, - right: view.frame.width - layoutFrame.origin.x - layoutFrame.width) - } - #endif #if os(iOS) || os(tvOS) public var safeArea: PEdgeInsets { @@ -129,6 +114,21 @@ public class PinLayout { return view.layoutMargins } #endif + + #if os(iOS) + public var keyboardMargins: PEdgeInsets { + guard #available(iOS 15.0, *) else { return .zero } + guard let view = view as? UIView else { return .zero } + + let layoutFrame = view.keyboardLayoutGuide.layoutFrame + guard !layoutFrame.isEmpty else { return .zero } + + return UIEdgeInsets(top: layoutFrame.origin.y, + left: layoutFrame.origin.x, + bottom: view.frame.height - layoutFrame.origin.y - layoutFrame.height, + right: view.frame.width - layoutFrame.origin.x - layoutFrame.width) + } + #endif // // MARK: Layout using distances from superview’s edges