mirror of
https://github.com/HackPlan/IQKeyboardManager.git
synced 2026-04-23 21:31:14 +08:00
Working on NavigationBar hidden issue #187
This commit is contained in:
@@ -35,11 +35,13 @@
|
||||
#import <UIKit/UITextField.h>
|
||||
#import <UIKit/UITextView.h>
|
||||
#import <UIKit/UITableViewController.h>
|
||||
#import <UIKit/UINavigationController.h>
|
||||
#import <UIKit/UITableView.h>
|
||||
#import <UIKit/UITouch.h>
|
||||
|
||||
#ifdef NSFoundationVersionNumber_iOS_5_1
|
||||
#import <UIKit/UICollectionView.h>
|
||||
#import <UIKit/NSLayoutConstraint.h>
|
||||
#endif
|
||||
|
||||
NSInteger const kIQDoneButtonToolbarTag = -1002;
|
||||
@@ -460,8 +462,24 @@ void _IQShowLog(NSString *logString);
|
||||
// Getting RootViewRect.
|
||||
CGRect rootViewRect = [[rootController view] frame];
|
||||
//Getting statusBarFrame
|
||||
CGFloat topLayoutGuide = 0;
|
||||
|
||||
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
|
||||
|
||||
switch (interfaceOrientation)
|
||||
{
|
||||
case UIInterfaceOrientationLandscapeLeft:
|
||||
case UIInterfaceOrientationLandscapeRight:
|
||||
topLayoutGuide = CGRectGetWidth(statusBarFrame);
|
||||
break;
|
||||
case UIInterfaceOrientationPortrait:
|
||||
case UIInterfaceOrientationPortraitUpsideDown:
|
||||
topLayoutGuide = CGRectGetHeight(statusBarFrame);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
CGFloat move = 0;
|
||||
// Move positive = textField is hidden.
|
||||
// Move negative = textField is showing.
|
||||
@@ -470,16 +488,16 @@ void _IQShowLog(NSString *logString);
|
||||
switch (interfaceOrientation)
|
||||
{
|
||||
case UIInterfaceOrientationLandscapeLeft:
|
||||
move = MIN(CGRectGetMinX(textFieldViewRect)-(CGRectGetWidth(statusBarFrame)+5), CGRectGetMaxX(textFieldViewRect)-(CGRectGetWidth(keyWindow.frame)-_kbSize.width));
|
||||
move = MIN(CGRectGetMinX(textFieldViewRect)-(topLayoutGuide+5), CGRectGetMaxX(textFieldViewRect)-(CGRectGetWidth(keyWindow.frame)-_kbSize.width));
|
||||
break;
|
||||
case UIInterfaceOrientationLandscapeRight:
|
||||
move = MIN(CGRectGetWidth(keyWindow.frame)-CGRectGetMaxX(textFieldViewRect)-(CGRectGetWidth(statusBarFrame)+5), _kbSize.width-CGRectGetMinX(textFieldViewRect));
|
||||
move = MIN(CGRectGetWidth(keyWindow.frame)-CGRectGetMaxX(textFieldViewRect)-(topLayoutGuide+5), _kbSize.width-CGRectGetMinX(textFieldViewRect));
|
||||
break;
|
||||
case UIInterfaceOrientationPortrait:
|
||||
move = MIN(CGRectGetMinY(textFieldViewRect)-(CGRectGetHeight(statusBarFrame)+5), CGRectGetMaxY(textFieldViewRect)-(CGRectGetHeight(keyWindow.frame)-_kbSize.height));
|
||||
move = MIN(CGRectGetMinY(textFieldViewRect)-(topLayoutGuide+5), CGRectGetMaxY(textFieldViewRect)-(CGRectGetHeight(keyWindow.frame)-_kbSize.height));
|
||||
break;
|
||||
case UIInterfaceOrientationPortraitUpsideDown:
|
||||
move = MIN(CGRectGetHeight(keyWindow.frame)-CGRectGetMaxY(textFieldViewRect)-(CGRectGetHeight(statusBarFrame)+5), _kbSize.height-CGRectGetMinY(textFieldViewRect));
|
||||
move = MIN(CGRectGetHeight(keyWindow.frame)-CGRectGetMaxY(textFieldViewRect)-(topLayoutGuide+5), _kbSize.height-CGRectGetMinY(textFieldViewRect));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -564,8 +582,42 @@ void _IQShowLog(NSString *logString);
|
||||
//Rearranging the expected Y offset according to the view.
|
||||
shouldOffsetY = MIN(shouldOffsetY, lastViewRect.origin.y/*-5*/); //-5 is for good UI.//Commenting -5 (Bug ID: #69)
|
||||
|
||||
//Subtracting the Y offset from the move variable, because we are going to change scrollView's contentOffset.y to shouldOffsetY.
|
||||
move -= (shouldOffsetY-superScrollView.contentOffset.y);
|
||||
//We're working on NavigationBar hidden issue
|
||||
// //[superScrollView superviewOfClassType:[UIScrollView class]] == 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 isKindOfClass:[UITextView class]] && [superScrollView superviewOfClassType:[UIScrollView class]] == nil && shouldOffsetY > 0)
|
||||
// {
|
||||
// CGFloat maintainTopLayout = 0;
|
||||
//
|
||||
// if ([_textFieldView.viewController respondsToSelector:@selector(topLayoutGuide)])
|
||||
// {
|
||||
// maintainTopLayout = [_textFieldView.viewController.topLayoutGuide length];
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// maintainTopLayout = _textFieldView.viewController.navigationController.navigationBar.frame.size.height;
|
||||
// }
|
||||
//
|
||||
// maintainTopLayout+= 20; //For good UI
|
||||
//
|
||||
// // Converting Rectangle according to window bounds.
|
||||
// CGRect expectedTextFieldViewRect = [[_textFieldView superview] convertRect:_textFieldView.frame toView:keyWindow];
|
||||
// expectedTextFieldViewRect.origin.y -= shouldOffsetY;
|
||||
//
|
||||
// if (expectedTextFieldViewRect.origin.y < maintainTopLayout)
|
||||
// {
|
||||
// shouldOffsetY -= maintainTopLayout - expectedTextFieldViewRect.origin.y; // removing -5 from current shouldOffsetY in order to make distance from NavigationBar
|
||||
// }
|
||||
//
|
||||
// move = 0;
|
||||
// }
|
||||
// else
|
||||
{
|
||||
//Subtracting the Y offset from the move variable, because we are going to change scrollView's contentOffset.y to shouldOffsetY.
|
||||
move -= (shouldOffsetY-superScrollView.contentOffset.y);
|
||||
}
|
||||
|
||||
|
||||
//Getting problem while using `setContentOffset:animated:`, So I used animation API.
|
||||
[UIView animateWithDuration:_animationDuration delay:0 options:(_animationCurve|UIViewAnimationOptionBeginFromCurrentState) animations:^{
|
||||
@@ -631,10 +683,12 @@ void _IQShowLog(NSString *logString);
|
||||
//Going ahead. No else if.
|
||||
}
|
||||
|
||||
//Special case for UITextView(Readjusting the move variable when textView hight is too big to fit on screen).
|
||||
//If we have permission to adjust the textView, then let's do it on behalf of user. (Enhancement ID: #15)
|
||||
//Added _isTextFieldViewFrameChanged. (Bug ID: #92)
|
||||
if (_canAdjustTextView && [_textFieldView isKindOfClass:[UITextView class]] && _keyboardManagerFlags.isTextFieldViewFrameChanged == NO)
|
||||
//Special case for UITextView(Readjusting the move variable when textView hight is too big to fit on screen)
|
||||
//_canAdjustTextView If we have permission to adjust the textView, then let's do it on behalf of user (Enhancement ID: #15)
|
||||
//_lastScrollView If not having inside any scrollView, (now contentInset manages the full screen textView.
|
||||
//[_textFieldView isKindOfClass:[UITextView class]] If is a UITextView type
|
||||
//_isTextFieldViewFrameChanged If frame is not change by library in past (Bug ID: #92)
|
||||
if (_canAdjustTextView && (_lastScrollView == NO) && [_textFieldView isKindOfClass:[UITextView class]] && _keyboardManagerFlags.isTextFieldViewFrameChanged == NO)
|
||||
{
|
||||
CGFloat textViewHeight = CGRectGetHeight(_textFieldView.frame);
|
||||
|
||||
@@ -642,11 +696,11 @@ void _IQShowLog(NSString *logString);
|
||||
{
|
||||
case UIInterfaceOrientationLandscapeLeft:
|
||||
case UIInterfaceOrientationLandscapeRight:
|
||||
textViewHeight = MIN(textViewHeight, (CGRectGetWidth(keyWindow.frame)-_kbSize.width-(CGRectGetWidth(statusBarFrame)+5)));
|
||||
textViewHeight = MIN(textViewHeight, (CGRectGetWidth(keyWindow.frame)-_kbSize.width-(topLayoutGuide+5)));
|
||||
break;
|
||||
case UIInterfaceOrientationPortrait:
|
||||
case UIInterfaceOrientationPortraitUpsideDown:
|
||||
textViewHeight = MIN(textViewHeight, (CGRectGetHeight(keyWindow.frame)-_kbSize.height-(CGRectGetHeight(statusBarFrame)+5)));
|
||||
textViewHeight = MIN(textViewHeight, (CGRectGetHeight(keyWindow.frame)-_kbSize.height-(topLayoutGuide+5)));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -687,10 +741,10 @@ void _IQShowLog(NSString *logString);
|
||||
{
|
||||
case UIInterfaceOrientationLandscapeLeft:
|
||||
case UIInterfaceOrientationLandscapeRight:
|
||||
minimumY = CGRectGetWidth(keyWindow.frame)-rootViewRect.size.height-statusBarFrame.size.width-(_kbSize.width-_keyboardDistanceFromTextField); break;
|
||||
minimumY = CGRectGetWidth(keyWindow.frame)-rootViewRect.size.height-topLayoutGuide-(_kbSize.width-_keyboardDistanceFromTextField); break;
|
||||
case UIInterfaceOrientationPortrait:
|
||||
case UIInterfaceOrientationPortraitUpsideDown:
|
||||
minimumY = (CGRectGetHeight(keyWindow.frame)-rootViewRect.size.height-statusBarFrame.size.height)/2-(_kbSize.height-_keyboardDistanceFromTextField); break;
|
||||
minimumY = (CGRectGetHeight(keyWindow.frame)-rootViewRect.size.height-topLayoutGuide)/2-(_kbSize.height-_keyboardDistanceFromTextField); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6751" systemVersion="14B25" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" initialViewController="En3-R6-bks">
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6751" systemVersion="13F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" initialViewController="En3-R6-bks">
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6736"/>
|
||||
@@ -1549,7 +1549,7 @@ textField.inputAcessoryView = [[UIView alloc] init];</string>
|
||||
</connections>
|
||||
</searchBar>
|
||||
<view contentMode="scaleToFill" id="SHK-82-xFg">
|
||||
<rect key="frame" x="10" y="161" width="305" height="269.99999959484421"/>
|
||||
<rect key="frame" x="10" y="161" width="305" height="269.99999927972311"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
|
||||
<subviews>
|
||||
<view contentMode="scaleToFill" id="k8L-Hj-hKb">
|
||||
@@ -1588,7 +1588,7 @@ textField.inputAcessoryView = [[UIView alloc] init];</string>
|
||||
<color key="backgroundColor" red="0.80000001192092896" green="1" blue="0.40000000596046448" alpha="1" colorSpace="calibratedRGB"/>
|
||||
</view>
|
||||
<view contentMode="scaleToFill" id="uYv-to-iCC">
|
||||
<rect key="frame" x="10" y="170" width="285" height="89.999999859753771"/>
|
||||
<rect key="frame" x="10" y="169.99999952904975" width="285" height="90"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<textField opaque="NO" clipsSubviews="YES" tag="102" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="TextField 4" minimumFontSize="17" id="yDj-sx-3pn">
|
||||
@@ -1760,7 +1760,7 @@ textField.inputAcessoryView = [[UIView alloc] init];</string>
|
||||
<scene sceneID="5Hs-En-g8p">
|
||||
<objects>
|
||||
<viewController automaticallyAdjustsScrollViewInsets="NO" id="Z1T-rR-mis" customClass="TextViewSpecialCaseViewController" sceneMemberID="viewController">
|
||||
<view key="view" contentMode="scaleToFill" id="AmX-Ef-2T2">
|
||||
<view key="view" contentMode="scaleToFill" id="AmX-Ef-2T2" customClass="UIScrollView">
|
||||
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<subviews>
|
||||
|
||||
Reference in New Issue
Block a user