0
我在一個滾動視圖, 有幾個UITextField
並通過設定每一次我得到了集中的任何文本框或取消鍵盤時的UITextField的邊界Flash的
layer.borderColor = ...,
layer.borderRadius = 3.0,
layer.borderWidth = 0.1,
layer.masksToBounds = YES.
- (void)keyboardWillShow:(NSNotification *)notification {
CGFloat animDuration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];
CGRect rect = [self.currentTextField superview].frame;
[UIView animateWithDuration:animDuration animations:^{
[self.scrollView scrollRectToVisible:rect animated:NO];
}];
}
- (void)keyboardWillHide:(NSNotification *)notification {
CGFloat animDuration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];
CGRect rect = [self.currentTextField superview].frame;
[UIView animateWithDuration:animDuration animations:^{
[self.scrollView scrollRectToVisible:rect animated:NO];
}];
}
的Bug,該文本框的所有邊境閃爍我的自定義文本框的邊界。但如果我只是滾動scrollView不閃爍
爲什麼你需要使用'[UIView的animateWithDuration:animDuration動畫: [se lf.scrollView scrollRectToVisible:rect animated:NO]; }];',爲什麼不使用'[self.scrollView scrollRectToVisible:rect animated:NO];'直接 – childrenOurFuture
@childrenOurFuture是正確的,嘗試在沒有UiView動畫的情況下滾動,但是動畫:YES – DoN1cK
首先當鍵盤顯示或隱藏,我需要使用鍵盤動畫持續時間相應地滾動scrollView。 –