弹出的视图内包含UITextView,当UITextView成为第一响应者后,视图上移的位置不准确
zhx039 opened this issue · 3 comments
当文本框成为第一响应者后,有可能多次接收到UIKeyboardWillChangeFrameNotification通知,
在通知处理方法(keyboardWillChangeFrame:)中,设置_popupView.center的Y值是根据当前Y值计算出来的,建议通过获取键盘前后位置差值来设置_popupView.center。
// if (!CGPointEqualToPoint(CGPointZero, _markerCenter)) {
// _popupView.center = CGPointMake(_markerCenter.x, _markerCenter.y - changeHeight);
// } else {
// _popupView.center = CGPointMake(_popupView.center.x, _popupView.center.y - changeHeight);
// }
CGRect beginKeyboardRect = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
CGRect endKeyboardRect = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat yOffset = endKeyboardRect.origin.y - beginKeyboardRect.origin.y;
_popupView.center = CGPointMake(_popupView.center.x, _popupView.center.y + yOffset - self.offsetSpacingOfKeyboard);
没看明白
if (!CGPointEqualToPoint(CGPointZero, _markerCenter)) {
_popupView.center = CGPointMake(_markerCenter.x, _markerCenter.y - changeHeight);
} else {
if ([self finishedCenter].y == _popupView.center.y) { //判断当前位置是否已经移动过。
_popupView.center = CGPointMake(_popupView.center.x, _popupView.center.y - changeHeight);
}
}
我这么改了下,目前还没发现问题,确实是,通知被调用了两次
if (!CGPointEqualToPoint(CGPointZero, _markerCenter)) {
_popupView.center = CGPointMake(_markerCenter.x, _markerCenter.y - changeHeight);
} else {
if ([self finishedCenter].y == _popupView.center.y) { //判断当前位置是否已经移动过。
_popupView.center = CGPointMake(_popupView.center.x, _popupView.center.y - changeHeight);
}
}
我这么改了下,目前还没发现问题,确实是,通知被调用了两次
谢谢,试了试是可以的