【问题标题】:view moves up on ipad but not every control moves on iphone视图在 ipad 上向上移动,但并非每个控件都在 iphone 上移动
【发布时间】:2012-07-22 08:31:12
【问题描述】:

我从堆栈溢出答案中实现了这个功能,第一个答案Move view when so that keyboard does not hide text field

//method to move the view up/down whenever the keyboard is shown/dismissed
-(void)setViewMovedUp:(BOOL)movedUp
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3]; // if you want to slide up the view

    CGRect rect = self.view.frame;
      if (movedUp)
    {
        // 1. move the view's origin up so that the text field that will be hidden come above the keyboard 
        // 2. increase the size of the view so that the area behind the keyboard is covered up.
        rect.origin.y -= kOFFSET_FOR_KEYBOARD;
        rect.size.height += kOFFSET_FOR_KEYBOARD;
    }
    else
    {
        // revert back to the normal state.
        rect.origin.y += kOFFSET_FOR_KEYBOARD;
        rect.size.height -= kOFFSET_FOR_KEYBOARD;
    }
    self.view.frame = rect;

    [UIView commitAnimations];
}

现在它在 ipad 上运行良好。我有一个文本框和它旁边的一些按钮,在它上面有一个带有聊天的文本视图。您使用文本框键入您的聊天。在 iphone 上,它会移动您输入的文本框和向上的按钮,但不会移动文本视图。事实上,它仍然覆盖了大部分窗口,并且按钮在窗口中间的顶部向上移动。

现在我今晚刚刚创建了 iphone 故事板视图(现在只有一个视图),并将我的所有控件都连接到它,以便在 ipad 上工作。现在该程序仍然可以在 ipad 上正常工作,甚至可以在显示键盘工作时向上移动视图。但在 iphone 上,它会移动除主控制台 UITextView 之外的所有内容。糟糕的是,在您键入时能够阅读文本:) 另外我想了解这里的理论。似乎如果我将视图定义为一个矩形并将其向上移动一些数字,例如 250,它应该全部移动。也许有更好的方法来做到这一点,比如首先准确地获取键盘尺寸,但我仍然希望它能够移动那个高度。

迈克

【问题讨论】:

    标签: iphone objective-c ipad ios5 ios-universal-app


    【解决方案1】:

    我添加了对纵向和横向的支持,但修复方法是在我移动框架后将 iPod 主控制台(文本视图)重置为纵向(我唯一的 iPod 方向)的位置(我唯一的 iPod 方向)。整个视图被移动了,所以我可以将它设置到同一个位置,它会在上下移动时进行平移。:

    double tall = 88;
    if(![self isTall])
    tall =0;
    if (movedUp)
    {
    // 1. move the view's origin up so that the text field that will be hidden come above the keyboard
    // 2. increase the size of the view so that the area behind the keyboard is covered up.
    rect.origin.y -= kOFFSET_FOR_KEYBOARD;
    rect.size.height += kOFFSET_FOR_KEYBOARD;
    self.view.frame = rect;
    if ( IDIOM != IPAD )
    self._mainConsole.frame = CGRectMake(5, 5, 310, 379 + tall);
    }
    else
    {
    // revert back to the normal state.
    rect.origin.y += kOFFSET_FOR_KEYBOARD;
    rect.size.height -= kOFFSET_FOR_KEYBOARD;
    self.view.frame = rect;
    if ( IDIOM != IPAD )
    self._mainConsole.frame = CGRectMake(5, 5, 310, 379 + tall);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-20
      • 2018-08-20
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多