UITextField自定义键盘和对设备方向的响应

问题描述:

我试图将自定义键盘附加到UITextField,并且键盘会响应不同的视图方向(横向,纵向等)。总之,问题是,当键盘确实出现时,当我旋转设备时响应视图方向时,键盘的尺寸全部搞乱了,我不太清楚如何设置键盘框架/边界正确。希望这里的某个人能帮我一把!UITextField自定义键盘和对设备方向的响应

这里是我的设计:

键盘从UIViewController中(从厦门国际银行)的一个子建。有两个视图: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的视图的界限,他们都没有解决问题。

有谁知道如何解决这个问题?还是有更好的自定义键盘设计模式?

谢谢!

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