Iftekhar 2 年 前
コミット
745e70bb4d

+ 4 - 0
Demo.xcodeproj/project.pbxproj

@@ -1373,7 +1373,9 @@
 				OTHER_SWIFT_FLAGS = "$(inherited)";
 				PRODUCT_BUNDLE_IDENTIFIER = com.iftekhar.IQKeyboardManagerSwift;
 				PRODUCT_NAME = DemoSwift;
+				SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
 				SUPPORTS_MACCATALYST = YES;
+				SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
 				SWIFT_OBJC_BRIDGING_HEADER = "Demo/Swift_Demo/Resources/IQKeyboardManger-Swift-Bridging-Header.h";
 				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
 				SWIFT_VERSION = 5.0;
@@ -1413,7 +1415,9 @@
 				OTHER_SWIFT_FLAGS = "$(inherited)";
 				PRODUCT_BUNDLE_IDENTIFIER = com.iftekhar.IQKeyboardManagerSwift;
 				PRODUCT_NAME = DemoSwift;
+				SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
 				SUPPORTS_MACCATALYST = YES;
+				SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
 				SWIFT_OBJC_BRIDGING_HEADER = "Demo/Swift_Demo/Resources/IQKeyboardManger-Swift-Bridging-Header.h";
 				SWIFT_VERSION = 5.0;
 				TARGETED_DEVICE_FAMILY = "1,2,6";

+ 1 - 1
Demo/Objective_C_Demo/Resources/Info.plist

@@ -35,7 +35,7 @@
 	<key>UIStatusBarHidden</key>
 	<false/>
 	<key>UIStatusBarStyle</key>
-	<string>UIStatusBarStyleDefault</string>
+	<string></string>
 	<key>UISupportedInterfaceOrientations</key>
 	<array>
 		<string>UIInterfaceOrientationPortrait</string>

+ 1 - 1
Demo/Swift_Demo/Resources/Info.plist

@@ -31,7 +31,7 @@
 	<key>UIStatusBarHidden</key>
 	<false/>
 	<key>UIStatusBarStyle</key>
-	<string>UIStatusBarStyleDefault</string>
+	<string></string>
 	<key>UISupportedInterfaceOrientations</key>
 	<array>
 		<string>UIInterfaceOrientationPortrait</string>

+ 3 - 3
Demo/Swift_Demo/ViewController/CollectionViewDemoController.swift

@@ -33,12 +33,12 @@ class CollectionViewDemoController: UIViewController, UICollectionViewDelegate,
         }
 
         if identifier == "SettingsNavigationController" {
-            
+
             let controller = segue.destination
-            
+
             controller.modalPresentationStyle = .popover
             controller.popoverPresentationController?.barButtonItem = sender as? UIBarButtonItem
-            
+
             let heightWidth = max(UIScreen.main.bounds.width, UIScreen.main.bounds.height)
             controller.preferredContentSize = CGSize(width: heightWidth, height: heightWidth)
             controller.popoverPresentationController?.delegate = self

+ 3 - 3
Demo/Swift_Demo/ViewController/CustomViewController.swift

@@ -197,12 +197,12 @@ class CustomViewController: UIViewController, UIPopoverPresentationControllerDel
         }
 
         if identifier == "SettingsNavigationController" {
-            
+
             let controller = segue.destination
-            
+
             controller.modalPresentationStyle = .popover
             controller.popoverPresentationController?.barButtonItem = sender as? UIBarButtonItem
-            
+
             let heightWidth = max(UIScreen.main.bounds.width, UIScreen.main.bounds.height)
             controller.preferredContentSize = CGSize(width: heightWidth, height: heightWidth)
             controller.popoverPresentationController?.delegate = self

+ 3 - 3
Demo/Swift_Demo/ViewController/ExampleTableViewController.swift

@@ -64,12 +64,12 @@ class ExampleTableViewController: UIViewController, UITableViewDataSource, UITab
         }
 
         if identifier == "SettingsNavigationController" {
-            
+
             let controller = segue.destination
-            
+
             controller.modalPresentationStyle = .popover
             controller.popoverPresentationController?.barButtonItem = sender as? UIBarButtonItem
-            
+
             let heightWidth = max(UIScreen.main.bounds.width, UIScreen.main.bounds.height)
             controller.preferredContentSize = CGSize(width: heightWidth, height: heightWidth)
             controller.popoverPresentationController?.delegate = self

+ 2 - 2
DemoExtension/ActionViewController.swift

@@ -26,7 +26,7 @@ class ActionViewController: UIViewController {
                 if provider.hasItemConformingToTypeIdentifier(kUTTypeImage as String) {
                     // This is an image. We'll load it, then place it in our image view.
                     weak var weakImageView = self.imageView
-                    provider.loadItem(forTypeIdentifier: kUTTypeImage as String, options: nil, completionHandler: { (imageURL, error) in
+                    provider.loadItem(forTypeIdentifier: kUTTypeImage as String, options: nil, completionHandler: { (imageURL, _) in
                         OperationQueue.main.addOperation {
                             if let strongImageView = weakImageView {
                                 if let imageURL = imageURL as? URL, let data =  try? Data(contentsOf: imageURL) {
@@ -39,7 +39,7 @@ class ActionViewController: UIViewController {
                     break
                 }
             }
-            if (imageFound) {
+            if imageFound {
                 // We only handle one image, so stop looking for more.
                 break
             }

+ 1 - 1
IQKeyboardManager/Categories/IQUITextFieldView+Additions.h

@@ -22,7 +22,7 @@
 // THE SOFTWARE.
 
 #import <UIKit/UIView.h>
-#import "IQKeyboardManagerConstants.h"
+#import <IQKeyboardManagerConstants.h>
 
 /**
  UIView category for managing UITextField/UITextView

+ 1 - 1
IQKeyboardManager/Categories/IQUIView+Hierarchy.h

@@ -23,7 +23,7 @@
 
 #import <UIKit/UIView.h>
 #import <UIKit/UIViewController.h>
-#import "IQKeyboardManagerConstants.h"
+#import <IQKeyboardManagerConstants.h>
 
 @class UICollectionView, UIScrollView, UITableView, UISearchBar, NSArray;
 

+ 12 - 12
IQKeyboardManager/IQKeyboardManager.h

@@ -21,18 +21,18 @@
 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 // THE SOFTWARE.
 
-#import "IQKeyboardManagerConstants.h"
-#import "IQUIView+IQKeyboardToolbar.h"
-#import "IQPreviousNextView.h"
-#import "IQUIViewController+Additions.h"
-#import "IQKeyboardReturnKeyHandler.h"
-#import "IQTextView.h"
-#import "IQToolbar.h"
-#import "IQUIScrollView+Additions.h"
-#import "IQUITextFieldView+Additions.h"
-#import "IQBarButtonItem.h"
-#import "IQTitleBarButtonItem.h"
-#import "IQUIView+Hierarchy.h"
+#import <IQKeyboardManagerConstants.h>
+#import <IQUIView+IQKeyboardToolbar.h>
+#import <IQPreviousNextView.h>
+#import <IQUIViewController+Additions.h>
+#import <IQKeyboardReturnKeyHandler.h>
+#import <IQTextView.h>
+#import <IQToolbar.h>
+#import <IQUIScrollView+Additions.h>
+#import <IQUITextFieldView+Additions.h>
+#import <IQBarButtonItem.h>
+#import <IQTitleBarButtonItem.h>
+#import <IQUIView+Hierarchy.h>
 
 #import <CoreGraphics/CGBase.h>
 

+ 4 - 2
IQKeyboardManager/IQKeyboardManager.m

@@ -636,8 +636,10 @@ NSInteger const kIQPreviousNextButtonToolbarTag     =   -1005;
         {
             cachedKeyWindow = originalKeyWindow;
         }
-        
-        return cachedKeyWindow;
+
+        __strong UIWindow *strongCachedKeyWindow = cachedKeyWindow;
+
+        return strongCachedKeyWindow;
     }
 }
 

+ 1 - 1
IQKeyboardManager/IQKeyboardReturnKeyHandler.h

@@ -21,7 +21,7 @@
 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 // THE SOFTWARE.
 
-#import "IQKeyboardManagerConstants.h"
+#import <IQKeyboardManagerConstants.h>
 
 #import <Foundation/NSObject.h>
 #import <Foundation/NSObjCRuntime.h>

+ 1 - 1
IQKeyboardManager/IQTextView/IQTextView.h

@@ -21,7 +21,7 @@
 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 // THE SOFTWARE.
 
-#import "IQKeyboardManagerConstants.h"
+#import <IQKeyboardManagerConstants.h>
 
 #import <UIKit/UITextView.h>
 

+ 2 - 2
IQKeyboardManager/IQToolbar/IQTitleBarButtonItem.h

@@ -21,8 +21,8 @@
 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 // THE SOFTWARE.
 
-#import "IQKeyboardManagerConstants.h"
-#import "IQBarButtonItem.h"
+#import <IQKeyboardManagerConstants.h>
+#import <IQBarButtonItem.h>
 
 #import <Foundation/NSObjCRuntime.h>
 

+ 1 - 1
IQKeyboardManager/IQToolbar/IQToolbar.h

@@ -21,7 +21,7 @@
 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 // THE SOFTWARE.
 
-#import "IQTitleBarButtonItem.h"
+#import <IQTitleBarButtonItem.h>
 
 #import <UIKit/UIToolbar.h>
 #import <UIKit/UIDevice.h>

+ 1 - 1
IQKeyboardManager/IQToolbar/IQUIView+IQKeyboardToolbar.h

@@ -21,7 +21,7 @@
 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 // THE SOFTWARE.
 
-#import "IQToolbar.h"
+#import <IQToolbar.h>
 
 #import <UIKit/UIView.h>
 #import <UIKit/UIImage.h>

+ 1 - 1
IQKeyboardManagerSwift/IQKeyboardManager+OrientationNotification.swift

@@ -50,7 +50,7 @@ internal extension IQKeyboardManager {
         showLog("****** \(#function) started ******", indentation: 1)
 
         //If textViewContentInsetChanged is saved then restore it.
-        if let textView = textFieldView as? UITextView, textView.responds(to: #selector(getter: UITextView.isEditable)) {
+        if let textView = textFieldView as? UIScrollView, textView.responds(to: #selector(getter: UITextView.isEditable)) {
 
             if isTextViewContentInsetChanged {
                 self.isTextViewContentInsetChanged = false

+ 42 - 8
IQKeyboardManagerSwift/IQKeyboardManager+Position.swift

@@ -222,13 +222,34 @@ public extension IQKeyboardManager {
 
         let layoutAreaHeight: CGFloat = rootController.view.layoutMargins.bottom
 
+        let isTextView: Bool
+        let isNonScrollableTextView: Bool
+
+        if let textView = textFieldView as? UIScrollView, textFieldView.responds(to: #selector(getter: UITextView.isEditable)) {
+
+            isTextView = true
+            isNonScrollableTextView = !textView.isScrollEnabled
+        } else {
+            isTextView = false
+            isNonScrollableTextView = false
+        }
+
         let topLayoutGuide: CGFloat = max(navigationBarAreaHeight, layoutAreaHeight) + 5
-        let bottomLayoutGuide: CGFloat = (textFieldView is UIScrollView && textFieldView.responds(to: #selector(getter: UITextView.isEditable))) ? 0 : rootController.view.layoutMargins.bottom  //Validation of textView for case where there is a tab bar at the bottom or running on iPhone X and textView is at the bottom.
+
+        let bottomLayoutGuide: CGFloat = (isTextView && !isNonScrollableTextView) ? 0 : rootController.view.layoutMargins.bottom  //Validation of textView for case where there is a tab bar at the bottom or running on iPhone X and textView is at the bottom.
+        let visibleHeight: CGFloat = window.frame.height-kbSize.height
 
         //  Move positive = textField is hidden.
         //  Move negative = textField is showing.
         //  Calculating move position.
-        var move: CGFloat = min(textFieldViewRectInRootSuperview.minY-(topLayoutGuide), textFieldViewRectInWindow.maxY-(window.frame.height-kbSize.height)+bottomLayoutGuide)
+        var move: CGFloat
+
+        //Special case: when the textView is not scrollable, then we'll be scrolling to the bottom part and let hide the top part above
+        if isNonScrollableTextView {
+            move = textFieldViewRectInWindow.maxY - visibleHeight + bottomLayoutGuide
+        } else {
+            move = min(textFieldViewRectInRootSuperview.minY-(topLayoutGuide), textFieldViewRectInWindow.maxY - visibleHeight + bottomLayoutGuide)
+        }
 
         showLog("Need to move: \(move)")
 
@@ -379,10 +400,18 @@ public extension IQKeyboardManager {
                     }
                 } else {
 
-                    shouldContinue = textFieldViewRectInRootSuperview.origin.y < topLayoutGuide
+                    if isNonScrollableTextView {
+                        shouldContinue = textFieldViewRectInWindow.maxY < visibleHeight + bottomLayoutGuide
+
+                        if shouldContinue {
+                            move = min(0,  textFieldViewRectInWindow.maxY -  visibleHeight + bottomLayoutGuide)
+                        }
+                    } else {
+                        shouldContinue = textFieldViewRectInRootSuperview.minY < topLayoutGuide
 
-                    if shouldContinue {
-                        move = min(0, textFieldViewRectInRootSuperview.origin.y - topLayoutGuide)
+                        if shouldContinue {
+                            move = min(0, textFieldViewRectInRootSuperview.minY - topLayoutGuide)
+                        }
                     }
                 }
 
@@ -408,13 +437,18 @@ public extension IQKeyboardManager {
                         var shouldOffsetY = scrollView.contentOffset.y - min(scrollView.contentOffset.y, -move)
 
                         //Rearranging the expected Y offset according to the view.
-                        shouldOffsetY = min(shouldOffsetY, lastViewRect.origin.y)
+
+                        if isNonScrollableTextView {
+                            shouldOffsetY = min(shouldOffsetY, lastViewRect.maxY - visibleHeight + bottomLayoutGuide)
+                        } else {
+                            shouldOffsetY = min(shouldOffsetY, lastViewRect.minY)
+                        }
 
                         //[_textFieldView isKindOfClass:[UITextView class]] If is a UITextView type
                         //nextScrollView == nil    If processing scrollView is last scrollView in upper hierarchy (there is no other scrollView upper hierrchy.)
                         //[_textFieldView isKindOfClass:[UITextView class]] If is a UITextView type
                         //shouldOffsetY >= 0     shouldOffsetY must be greater than in order to keep distance from navigationBar (Bug ID: #92)
-                        if (textFieldView is UIScrollView && textFieldView.responds(to: #selector(getter: UITextView.isEditable))),
+                        if isTextView, !isNonScrollableTextView,
                             nextScrollView == nil,
                             shouldOffsetY >= 0 {
 
@@ -422,7 +456,7 @@ public extension IQKeyboardManager {
                             if let currentTextFieldViewRect = textFieldView.superview?.convert(textFieldView.frame, to: window) {
 
                                 //Calculating expected fix distance which needs to be managed from navigation bar
-                                let expectedFixDistance = currentTextFieldViewRect.minY - topLayoutGuide
+                                let expectedFixDistance: CGFloat = currentTextFieldViewRect.minY - topLayoutGuide
 
                                 //Now if expectedOffsetY (superScrollView.contentOffset.y + expectedFixDistance) is lower than current shouldOffsetY, which means we're in a position where navigationBar up and hide, then reducing shouldOffsetY with expectedOffsetY (superScrollView.contentOffset.y + expectedFixDistance)
                                 shouldOffsetY = min(shouldOffsetY, scrollView.contentOffset.y + expectedFixDistance)

+ 0 - 1
IQKeyboardManagerSwift/IQToolbar/IQBarButtonItem.swift

@@ -102,6 +102,5 @@ import UIKit
 
     deinit {
         target = nil
-        invocation = nil
     }
 }

+ 0 - 3
IQKeyboardManagerSwift/IQToolbar/IQTitleBarButtonItem.swift

@@ -163,8 +163,5 @@ import UIKit
 
     deinit {
         customView = nil
-        titleButton?.removeTarget(nil, action: nil, for: .touchUpInside)
-        _titleView = nil
-        titleButton = nil
     }
 }

+ 0 - 10
IQKeyboardManagerSwift/IQToolbar/IQToolbar.swift

@@ -257,14 +257,4 @@ import UIKit
     @objc open var enableInputClicksWhenVisible: Bool {
         return true
     }
-
-    deinit {
-
-        items = nil
-        privatePreviousBarButton = nil
-        privateNextBarButton = nil
-        privateTitleBarButton = nil
-        privateDoneBarButton = nil
-        privateFixedSpaceBarButton = nil
-    }
 }