【发布时间】:2016-11-06 21:01:24
【问题描述】:
我在滚动视图中有几个UITextField,
我通过设置自定义 textFields 的边框
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];
}];
}
每次我让任何文本字段聚焦或关闭键盘时,所有文本字段的边框都会闪烁。但是如果我只是滚动滚动视图就不会闪烁
【问题讨论】:
-
为什么要使用
[UIView animateWithDuration:animDuration animations:^{ [self.scrollView scrollRectToVisible:rect animated:NO]; }];,为什么不直接使用[self.scrollView scrollRectToVisible:rect animated:NO]; -
@childrenOurFuture 是对的,尝试在没有 UiView 动画的情况下滚动,但使用动画:YES
-
首先当键盘显示或隐藏时,我需要滚动视图与键盘动画持续时间相应地滚动。
-
第二次评论这两种方法,问题依旧
标签: ios uiscrollview uitextfield