我有 UIView - UIScrollView - UITextField
如果出现键盘(textField 委托),我将 self.view 向上移动一些偏移值。但是,相同的值如何在 LandscapeLeft 和 LandscapeRight 中产生不同的偏移量?在 LandscapeLeft 中,它工作正常(底部图片)。似乎有 20px 的差异(与 statusBar 高度重合?)
如何解决?(不接受硬编码+20作为答案)感谢您的帮助。
// AHTextFieldHelper.m
...
- (void)moveViewUp:(UIView *)view withOffset:(int)offset forOrientation:(Orientation)orientation withDuration:(float)animationDuration
{
_animationDuration = animationDuration;
_view = view;
_offset = offset;
_orientation = orientation;
[UIView animateWithDuration:animationDuration delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
if (orientation == portrait)
{
_tempPortraitRect = view.frame;
view.frame = CGRectOffset(view.frame, view.frame.origin.x, view.frame.origin.y - offset);
}
else if (orientation == landscapeLeft)
{
_tempLandscapeLeftRect = view.frame;
view.frame = CGRectOffset(view.frame, view.frame.origin.x + offset, view.frame.origin.y);
}
else if (orientation == landscapeRight)
{
_tempLandscapeRightRect = view.frame;
view.frame = CGRectOffset(view.frame, view.frame.origin.x - offset, view.frame.origin.y);
}
} completion:^(BOOL finished){
_isUP = YES;
}];
}
ViewController.m - (void)textFieldDidBeginEditing:(UITextField *)textField
// ViewController.m - (void)textFieldDidBeginEditing:(UITextField *)textField
// some refactoring needed
if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)
{
_originalLandscapeRightFrame = self.view.frame;
CGPoint translatedTextFieldOrigin = [[textField superview] convertPoint:textField.frame.origin toView:self.view];
if (fabs(translatedTextFieldOrigin.y) >= ([RSHelpersFunctions screenResolution].width - kAHiPhoneLandscapeKeyboardHeight) - textField.frame.size.height)
{
CGFloat newPoint = (translatedTextFieldOrigin.y - ([RSHelpersFunctions screenResolution].width - kAHiPhoneLandscapeKeyboardHeight)) + textField.frame.size.height + 30 + 20; // quick fix
_textFieldHelper = [AHTextFieldHelper new];
[_textFieldHelper moveViewUp:self.view withOffset:fabs(newPoint) forOrientation:landscapeRight withDuration:0.5];
}
}
else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft)
{
_originalLandscapeLeftFrame = self.view.frame;
CGPoint translatedTextFieldOrigin = [[textField superview] convertPoint:textField.frame.origin toView:self.view];
if (fabs(translatedTextFieldOrigin.y) >= ([RSHelpersFunctions screenResolution].width - kAHiPhoneLandscapeKeyboardHeight) - textField.frame.size.height)
{
CGFloat newPoint = (translatedTextFieldOrigin.y - ([RSHelpersFunctions screenResolution].width - kAHiPhoneLandscapeKeyboardHeight)) + textField.frame.size.height + 30;
_textFieldHelper = [AHTextFieldHelper new];
[_textFieldHelper moveViewUp:self.view withOffset:fabs(newPoint) forOrientation:landscapeLeft withDuration:0.5];
}
}