Skip to content

Commit 3c0a9b4

Browse files
committed
私信页面 - 键盘弹起时的滚动优化
1 parent 04c7255 commit 3c0a9b4

1 file changed

Lines changed: 23 additions & 17 deletions

File tree

Coding_iOS/Controllers/ConversationViewController.m

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,19 @@ - (void)messageInputView:(UIMessageInputView *)inputView heightToBottomChenged:(
152152
self.myTableView.contentInset = contentInsets;
153153
self.myTableView.scrollIndicatorInsets = contentInsets;
154154
//调整内容
155+
static CGPoint keyboard_down_ContentOffset;
156+
static CGFloat keyboard_down_InputViewHeight;
155157
if (heightToBottom > CGRectGetHeight(inputView.frame)) {
156-
CGPoint contentOffset = self.myTableView.contentOffset;
157-
CGFloat spaceHeight = MAX(0, CGRectGetHeight(self.myTableView.frame) - self.myTableView.contentSize.height - CGRectGetHeight(inputView.frame));
158-
contentOffset.y += MAX(0, heightToBottom - CGRectGetHeight(inputView.frame) - spaceHeight);
158+
CGPoint contentOffset = keyboard_down_ContentOffset;
159+
CGFloat spaceHeight = MAX(0, CGRectGetHeight(self.myTableView.frame) - self.myTableView.contentSize.height - keyboard_down_InputViewHeight);
160+
contentOffset.y += MAX(0, heightToBottom - keyboard_down_InputViewHeight - spaceHeight);
161+
NSLog(@"\nspaceHeight:%.2f heightToBottom:%.2f diff:%.2f Y:%.2f", spaceHeight, heightToBottom, MAX(0, heightToBottom - CGRectGetHeight(inputView.frame) - spaceHeight), contentOffset.y);
159162
[UIView animateWithDuration:0.25 delay:0.0f options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{
160163
self.myTableView.contentOffset = contentOffset;
161164
} completion:nil];
165+
}else{
166+
keyboard_down_ContentOffset = self.myTableView.contentOffset;
167+
keyboard_down_InputViewHeight = CGRectGetHeight(inputView.frame);
162168
}
163169
}
164170

@@ -212,20 +218,20 @@ - (void)stopPolling{
212218
}
213219

214220
- (void)doPoll{
215-
if (!_myPriMsgs || _myPriMsgs.isLoading) {
216-
return;
217-
}
218-
if (_myPriMsgs.list.count <= 0) {
219-
[self refreshLoadMore:NO];
220-
return;
221-
}
222-
__weak typeof(self) weakSelf = self;
223-
[[Coding_NetAPIManager sharedManager] request_Fresh_PrivateMessages:_myPriMsgs andBlock:^(id data, NSError *error) {
224-
if (data && [(NSArray *)data count] > 0) {
225-
[weakSelf.myPriMsgs configWithPollArray:data];
226-
[weakSelf dataChangedWithError:NO scrollToBottom:YES animated:YES];
227-
}
228-
}];
221+
// if (!_myPriMsgs || _myPriMsgs.isLoading) {
222+
// return;
223+
// }
224+
// if (_myPriMsgs.list.count <= 0) {
225+
// [self refreshLoadMore:NO];
226+
// return;
227+
// }
228+
// __weak typeof(self) weakSelf = self;
229+
// [[Coding_NetAPIManager sharedManager] request_Fresh_PrivateMessages:_myPriMsgs andBlock:^(id data, NSError *error) {
230+
// if (data && [(NSArray *)data count] > 0) {
231+
// [weakSelf.myPriMsgs configWithPollArray:data];
232+
// [weakSelf dataChangedWithError:NO scrollToBottom:YES animated:YES];
233+
// }
234+
// }];
229235
}
230236

231237
#pragma mark Table M

0 commit comments

Comments
 (0)