![](/img/trans.png)
[英]What is a good practice to adjust/moving view up and down when keyboard is shown, without using a scroll view(iOS)?
[英]swiping with UIScrollView and moving up the view when using keyboard
在TPKeyboardAvoidingScrollView.m中有一個方法(keyboardWillHide :),當鍵盤要隱藏時會調用它。 在該方法中,scrollview的內容偏移設置為CGPointZero,因此您的scrollview將轉到第一個視圖控制器。
- (void)keyboardWillHide:(NSNotification*)notification {
_keyboardRect = CGRectZero;
_keyboardVisible = NO;
// Restore dimensions to prior size
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:[[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]];
[UIView setAnimationDuration:[[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]];
self.contentInset = _priorInset;
//self.contentOffset = CGPointZero;//Replacing this with below line
self.contentOffset = CGPointMake(self.contentOffset.x, 0);
[self setScrollIndicatorInsets:self.contentInset];
_priorInsetSaved = NO;
[UIView commitAnimations];
}
要在編輯文本字段時停止滾動 -
- (void)keyboardDidShow:(NSNotification*)notification {
[self setScrollEnabled:NO];
//existing code
}
- (void)keyboardWillHide:(NSNotification*)notification {
[self setScrollEnabled:YES];
//existing code with modification of content offset
}
請記住,這可能會影響您使用TPKeyboardAvoidingScrollView對象的其他視圖。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.