【问题标题】:UITextField Custom Keyboard and Response to Device OrientationUITextField 自定义键盘和对设备方向的响应
【发布时间】:2011-05-12 19:51:30
【问题描述】:

我正在尝试将自定义键盘附加到 UITextField,并且键盘会响应不同的视图方向(横向、纵向等)。简而言之,问题是虽然键盘确实出现了,但当我旋转设备时响应视图方向时,键盘的尺寸都搞砸了,我不太确定如何设置键盘框架/边界正确。希望这里有人能帮帮我!

这是我的设计:

键盘是从 UIViewController 的子类(来自 xib)构建的。有两个视图:landscapeKeyboardView 和 PortraitKeyboardView。

键盘通过属性“inputView”附加到 UITextField。

键盘视图的旋转在函数中完成:

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientationduration:(NSTimeInterval)duration
{
    if ((toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)) 
    {
        self.view = self.landscapeKeyboardView;
    }else if((toInterfaceOrientation == UIInterfaceOrientationPortrait) || (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))
    {
        self.view = self.portraitKeyboardView;
    }
}

旋转确实发生了,但是旋转后视图尺寸都搞砸了。我还尝试手动设置 self.view 或 LandscapeKeyboardView 或 PortraitKeyboardView 的框架或视图边界,但似乎都没有解决问题。

有人知道如何解决这个问题吗?或者自定义键盘有更好的设计模式吗?

谢谢!

【问题讨论】:

    标签: ios keyboard uitextfield


    【解决方案1】:

    您可能需要翻译 CGRect 以进行旋转。 UIView 有许多用于转换矩形和点的实例方法。它考虑了另一个视图框架之外的视图(例如,找出键盘矩形在 UIPopover 下方的距离)以及旋转。 convertRect:fromView: 只是一个例子,但它们都以 '​​convert' 开头。

    【讨论】:

      猜你喜欢
      • 2014-12-26
      • 1970-01-01
      • 2016-06-30
      • 2011-03-16
      • 1970-01-01
      • 2016-03-28
      • 2011-01-19
      • 2011-05-18
      • 2018-05-02
      相关资源
      最近更新 更多