私は 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];
}
}