ios - iPad-物镜-C-键盘-一切都从左向右移动,而不是向下移动

标签 ios objective-c ipad

我希望这个问题有意义,我有一个登录屏幕,当我单击一个输入字段(“用户名”或“密码”)时,将出现一个键盘。但是当这种情况发生时,一切都会从左到右运动,所以我在左侧有一个很大的空白。我期望的是一切都将从向下移动。我真的希望这是有道理的。这是我的代码:

- (void)animateTextField:(UITextField *) textField up: (BOOL) up;
- (void)NavButtonPressed: (UIButton*)sender;

- (void)NavButtonPressed: (UIButton*)sender
{
    if([sender isEqual:navBarNextButton])
    {
        [self.idTextField resignFirstResponder];
        [self.passwordTextField becomeFirstResponder];
        currentResponder = 1;
        [self animateTextField:self.passwordTextField up:NO];
        [self animateTextField:self.passwordTextField up:YES];
        [navBarNextButton setEnabled:NO];
        [navBarPrevButton setEnabled:YES];

    }
    else
    {
        [self.passwordTextField resignFirstResponder];
        [self.idTextField becomeFirstResponder];
        currentResponder = 0;
        [self animateTextField:self.idTextField up:NO];
        [self animateTextField:self.idTextField up:YES];
        [navBarNextButton setEnabled:YES];
        [navBarPrevButton setEnabled:NO];
    }
}

- (void)animateTextField:(UITextField *) textField up: (BOOL) up
{
    int movementDistance;
    if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
    {
        if([textField isEqual:self.idTextField])
        {
            [textfieldNavigatorView setFrame:CGRectMake(0.0f, (1024.0f/2.0f)-31.5f, 1024.0f, 45.0f)];
            movementDistance = 110;
        }
        else
        {
            [textfieldNavigatorView setFrame:CGRectMake(0.0f, (1024.0f/2.0f)-26.5f, 1024.0f, 45.0f)];
            movementDistance = 115;
        }
    }
    else
    {movementDistance = 0;}

    const float movementDuration = 0.3f;
    int movement=0;
    if([self interfaceOrientation] == UIInterfaceOrientationLandscapeLeft)
        movement = (up? -movementDistance : movementDistance);
    if([self interfaceOrientation] == UIInterfaceOrientationLandscapeRight)
        movement = (up? movementDistance : -movementDistance);

    [UIView beginAnimations:@"keyboardtransition" context:nil];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDuration:movementDuration];
    self.view.frame = CGRectOffset(self.view.frame, movement, 0);

    [UIView commitAnimations];
}

如果有人可以帮助,那将是惊人的。我的项目设备设置为仅横向权限。

最佳答案

我之前遇到过同样的问题,在iOS 7和8中,它的工作方式有所不同。因此,我实现了一种处理该问题的方法:

- (void)keyboardHideShow:(UIView *)view shiftBy:(float)shiftAmount forState:(BOOL)state
{
    float keyBoardOffset = shiftAmount;
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3]; // if you want to slide up the view
    [UIView setAnimationBeginsFromCurrentState:YES];
    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    CGRect rect = [[[UIApplication sharedApplication] keyWindow] bounds];
    if (state)
    {
        if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8)
        {
            if (orientation == UIInterfaceOrientationLandscapeLeft)
            {
                rect.origin.x -= keyBoardOffset;
            }
            else
            {
                rect.origin.x += keyBoardOffset;
            }
        }
        else
        {
            rect.origin.y -= keyBoardOffset;
        }
    }
    view.frame = rect;
    [UIView commitAnimations];
}

您可以这样称呼它:
[self keyboardHideShow:textfieldNavigatorView shiftBy:31.5 forState:true];  // For up
[self keyboardHideShow:textfieldNavigatorView shiftBy:31.5 forState:false]; // For down

关于ios - iPad-物镜-C-键盘-一切都从左向右移动,而不是向下移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27611236/

相关文章:

objective-c - 点击手势事件未在UIImageView上触发

ios - Xcode 6-基础国际化-导出和导入en.xliff文件

swift - 使用 SKPhysics 在 iPad Pro 12.9 上设置屏幕边界

iOS iPad 应用程序不隐藏键盘

iphone - 添加到窗口后自动调整 UIView 的大小

ios - Swift - UINavigationController 栏颜色不会以编程方式更改

iOs 从保存状态打开应用

iphone - iOS - CAKeyFrameAnimation - 不播放

ios - UIScrollView 内部一致性崩溃

ios - iOS MultipeerConnectivity 框架中的 session 加密