From e30063e24ea7f97b53d1b8a3d29f022f32e97d93 Mon Sep 17 00:00:00 2001 From: nwn1 <815961972@qq.com> Date: Wed, 15 Jan 2025 14:41:43 +0800 Subject: [PATCH] fix: ios 14 Bug --- Demo.xcodeproj/project.pbxproj | 16 +- IQKeyboardManager/IQKeyboardManager.m | 256 ++++++++++++++------------ Podfile.lock | 2 +- 3 files changed, 143 insertions(+), 131 deletions(-) diff --git a/Demo.xcodeproj/project.pbxproj b/Demo.xcodeproj/project.pbxproj index 11079981..b8d57649 100644 --- a/Demo.xcodeproj/project.pbxproj +++ b/Demo.xcodeproj/project.pbxproj @@ -2444,10 +2444,9 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES; CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = "$(inherited)"; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CODE_SIGN_STYLE = Manual; + CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = ""; - "DEVELOPMENT_TEAM[sdk=iphoneos*]" = 7UUTF6T5P9; GCC_C_LANGUAGE_STANDARD = c99; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = ""; @@ -2457,7 +2456,7 @@ GCC_WARN_UNUSED_LABEL = YES; GCC_WARN_UNUSED_PARAMETER = NO; INFOPLIST_FILE = Demo/Objective_C_Demo/Resources/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 15.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -2467,7 +2466,6 @@ PRODUCT_NAME = IQKeyboardManagerDemo; PROVISIONING_PROFILE = ""; PROVISIONING_PROFILE_SPECIFIER = ""; - "PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = infoenumapps; SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; SUPPORTS_MACCATALYST = NO; SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; @@ -2490,10 +2488,9 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES; CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = "$(inherited)"; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CODE_SIGN_STYLE = Manual; + CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = ""; - "DEVELOPMENT_TEAM[sdk=iphoneos*]" = 7UUTF6T5P9; GCC_C_LANGUAGE_STANDARD = c99; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = ""; @@ -2503,7 +2500,7 @@ GCC_WARN_UNUSED_LABEL = YES; GCC_WARN_UNUSED_PARAMETER = NO; INFOPLIST_FILE = Demo/Objective_C_Demo/Resources/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 15.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -2513,7 +2510,6 @@ PRODUCT_NAME = IQKeyboardManagerDemo; PROVISIONING_PROFILE = ""; PROVISIONING_PROFILE_SPECIFIER = ""; - "PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = infoenumapps; SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; SUPPORTS_MACCATALYST = NO; SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; diff --git a/IQKeyboardManager/IQKeyboardManager.m b/IQKeyboardManager/IQKeyboardManager.m index 72325eab..f3a191cf 100644 --- a/IQKeyboardManager/IQKeyboardManager.m +++ b/IQKeyboardManager/IQKeyboardManager.m @@ -1365,10 +1365,9 @@ - (void)reloadLayoutIfNeeded #pragma mark - UIKeyboard Notification methods /* UIKeyboardWillShowNotification. */ --(void)keyboardWillShow:(NSNotification*)aNotification -{ +-(void) c_keyboardWillShow:(NSNotification*)aNotification{ _kbShowNotification = aNotification; - + // Boolean to know keyboard is showing/hiding _keyboardShowing = YES; @@ -1403,7 +1402,7 @@ -(void)keyboardWillShow:(NSNotification*)aNotification _topViewBeginSafeAreaInsets = UIEdgeInsetsZero; return; } - + CFTimeInterval startTime = CACurrentMediaTime(); [self showLog:[NSString stringWithFormat:@">>>>> %@ started >>>>>",NSStringFromSelector(_cmd)] indentation:1]; @@ -1447,128 +1446,145 @@ -(void)keyboardWillShow:(NSNotification*)aNotification CFTimeInterval elapsedTime = CACurrentMediaTime() - startTime; [self showLog:[NSString stringWithFormat:@"<<<<< %@ ended: %g seconds <<<<<",NSStringFromSelector(_cmd),elapsedTime] indentation:-1]; } +-(void)keyboardWillShow:(NSNotification*)aNotification +{ + dispatch_async(dispatch_get_main_queue(), ^{ + [self c_keyboardWillShow:aNotification]; + }); + +} /* UIKeyboardWillHideNotification. So setting rootViewController to it's default frame. */ + +- (void)c_keyboardWillHide:(NSNotification*)aNotification{ + + if (aNotification) _kbShowNotification = nil; + + // Boolean to know keyboard is showing/hiding + _keyboardShowing = NO; + + // Getting keyboard animation duration + CGFloat duration = [[aNotification userInfo][UIKeyboardAnimationDurationUserInfoKey] floatValue]; + if (duration!= 0.0f) + { + _animationDuration = duration; + } + else + { + _animationDuration = 0.25; + } + + //If not enabled then do nothing. + if ([self privateIsEnabled] == NO) return; + + CFTimeInterval startTime = CACurrentMediaTime(); + [self showLog:[NSString stringWithFormat:@">>>>> %@ started >>>>>",NSStringFromSelector(_cmd)] indentation:1]; + + [self showLog:[NSString stringWithFormat:@"Notification Object: %@", NSStringFromClass([aNotification.object class])]]; + + //Commented due to #56. Added all the conditions below to handle WKWebView's textFields. (Bug ID: #56) + // We are unable to get textField object while keyboard showing on WKWebView's textField. (Bug ID: #11) + // if (_textFieldView == nil) return; + + //Restoring the contentOffset of the lastScrollView + __strong __typeof__(UIScrollView) *strongLastScrollView = _lastScrollView; + + if (strongLastScrollView) + { + __weak __typeof__(self) weakSelf = self; + __weak __typeof__(UIView) *weakTextFieldView = self.textFieldView; + + [UIView animateWithDuration:_animationDuration delay:0 options:(_animationCurve|UIViewAnimationOptionBeginFromCurrentState) animations:^{ + + __strong __typeof__(self) strongSelf = weakSelf; + __strong __typeof__(UIView) *strongTextFieldView = weakTextFieldView; + + if (UIEdgeInsetsEqualToEdgeInsets(strongLastScrollView.contentInset, strongSelf.startingContentInsets) == NO) + { + [strongSelf showLog:[NSString stringWithFormat:@"Restoring ScrollView contentInset to : %@",NSStringFromUIEdgeInsets(strongSelf.startingContentInsets)]]; + + strongLastScrollView.contentInset = strongSelf.startingContentInsets; + strongLastScrollView.scrollIndicatorInsets = strongSelf.startingScrollIndicatorInsets; + } + + if (strongLastScrollView.shouldRestoreScrollViewContentOffset && CGPointEqualToPoint(strongLastScrollView.contentOffset, strongSelf.startingContentOffset) == NO) + { + [strongSelf showLog:[NSString stringWithFormat:@"Restoring ScrollView contentOffset to : %@",NSStringFromCGPoint(strongSelf.startingContentOffset)]]; + + // (Bug ID: #1365, #1508, #1541) + UIStackView *stackView = [strongTextFieldView superviewOfClassType:[UIStackView class] belowView:strongLastScrollView]; + BOOL animatedContentOffset = stackView != nil || [strongLastScrollView isKindOfClass:[UICollectionView class]]; + + if (animatedContentOffset) + { + [strongLastScrollView setContentOffset:strongSelf.startingContentOffset animated:UIView.areAnimationsEnabled]; + } + else + { + strongLastScrollView.contentOffset = strongSelf.startingContentOffset; + } + } + + // TODO: restore scrollView state + // This is temporary solution. Have to implement the save and restore scrollView state + UIScrollView *superScrollView = strongLastScrollView; + do + { + CGSize contentSize = CGSizeMake(MAX(superScrollView.contentSize.width, CGRectGetWidth(superScrollView.frame)), MAX(superScrollView.contentSize.height, CGRectGetHeight(superScrollView.frame))); + + CGFloat minimumY = contentSize.height-CGRectGetHeight(superScrollView.frame); + + if (minimumY>>>> %@ started >>>>>",NSStringFromSelector(_cmd)] indentation:1]; - - [self showLog:[NSString stringWithFormat:@"Notification Object: %@", NSStringFromClass([aNotification.object class])]]; - - //Commented due to #56. Added all the conditions below to handle WKWebView's textFields. (Bug ID: #56) - // We are unable to get textField object while keyboard showing on WKWebView's textField. (Bug ID: #11) -// if (_textFieldView == nil) return; - - //Restoring the contentOffset of the lastScrollView - __strong __typeof__(UIScrollView) *strongLastScrollView = _lastScrollView; - - if (strongLastScrollView) - { - __weak __typeof__(self) weakSelf = self; - __weak __typeof__(UIView) *weakTextFieldView = self.textFieldView; - - [UIView animateWithDuration:_animationDuration delay:0 options:(_animationCurve|UIViewAnimationOptionBeginFromCurrentState) animations:^{ - - __strong __typeof__(self) strongSelf = weakSelf; - __strong __typeof__(UIView) *strongTextFieldView = weakTextFieldView; - - if (UIEdgeInsetsEqualToEdgeInsets(strongLastScrollView.contentInset, strongSelf.startingContentInsets) == NO) - { - [strongSelf showLog:[NSString stringWithFormat:@"Restoring ScrollView contentInset to : %@",NSStringFromUIEdgeInsets(strongSelf.startingContentInsets)]]; - - strongLastScrollView.contentInset = strongSelf.startingContentInsets; - strongLastScrollView.scrollIndicatorInsets = strongSelf.startingScrollIndicatorInsets; - } - - if (strongLastScrollView.shouldRestoreScrollViewContentOffset && CGPointEqualToPoint(strongLastScrollView.contentOffset, strongSelf.startingContentOffset) == NO) - { - [strongSelf showLog:[NSString stringWithFormat:@"Restoring ScrollView contentOffset to : %@",NSStringFromCGPoint(strongSelf.startingContentOffset)]]; - - // (Bug ID: #1365, #1508, #1541) - UIStackView *stackView = [strongTextFieldView superviewOfClassType:[UIStackView class] belowView:strongLastScrollView]; - BOOL animatedContentOffset = stackView != nil || [strongLastScrollView isKindOfClass:[UICollectionView class]]; - - if (animatedContentOffset) - { - [strongLastScrollView setContentOffset:strongSelf.startingContentOffset animated:UIView.areAnimationsEnabled]; - } - else - { - strongLastScrollView.contentOffset = strongSelf.startingContentOffset; - } - } - - // TODO: restore scrollView state - // This is temporary solution. Have to implement the save and restore scrollView state - UIScrollView *superScrollView = strongLastScrollView; - do - { - CGSize contentSize = CGSizeMake(MAX(superScrollView.contentSize.width, CGRectGetWidth(superScrollView.frame)), MAX(superScrollView.contentSize.height, CGRectGetHeight(superScrollView.frame))); - - CGFloat minimumY = contentSize.height-CGRectGetHeight(superScrollView.frame); - - if (minimumY)identifier sizeHandler:(void (^_Nonnull)(CGSize size))sizeHandler diff --git a/Podfile.lock b/Podfile.lock index 8da234a1..164d5381 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -90,4 +90,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: e614b88580b21d28b61be6f469e20fbe893f1525 -COCOAPODS: 1.16.0 +COCOAPODS: 1.15.2