Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

弹出的视图内包含UITextView,当UITextView成为第一响应者后,视图上移的位置不准确 #42

Open
zhx039 opened this issue Sep 28, 2018 · 3 comments

Comments

@zhx039
Copy link

zhx039 commented Sep 28, 2018

当文本框成为第一响应者后,有可能多次接收到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);
@Liyongcong
Copy link

没看明白

@NBTech6688
Copy link

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);
}
}
我这么改了下,目前还没发现问题,确实是,通知被调用了两次

@Liyongcong
Copy link

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);
}
}
我这么改了下,目前还没发现问题,确实是,通知被调用了两次

谢谢,试了试是可以的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants