7

好吧,在发布这个问题之前,我已经进行了一些体面的检查,但未能找到正确的答案。我无法在这里真正解释我的整个应用场景,因为解释起来有点复杂。所以,让我把这个问题说得很简单。如何更改 .ie 的框架,UIKeyBoard我希望UIKeyBoard 向上旋转或平移 90 度以支持我的视图位置。我有出路吗?

4

1 回答 1

4

您无法更改默认键盘。但是,您可以通过将其设置为打开来创建自定义 UIView 以用作键盘替换inputView,例如 UITextField。

虽然创建自定义键盘需要一些时间,但它适用于较旧的 iOS 版本(inputView在 iOS 3.2 及更高版本中可用的 UITextField 上)并支持物理键盘(如果连接了键盘,则键盘会自动隐藏)。

下面是一些创建垂直键盘的示例代码:

界面:

#import <UIKit/UIKit.h>

@interface CustomKeyboardView : UIView

@property (nonatomic, strong) UIView *innerInputView;
@property (nonatomic, strong) UIView *underlayingView;

- (id)initForUnderlayingView:(UIView*)underlayingView;

@end

执行:

#import "CustomKeyboardView.h"

@implementation CustomKeyboardView

@synthesize innerInputView=_innerInputView;
@synthesize underlayingView=_underlayingView;

- (id)initForUnderlayingView:(UIView*)underlayingView
{
    //  Init a CustomKeyboardView with the size of the underlying view
    //  You might want to set an autoresizingMask on the innerInputView.
    self = [super initWithFrame:underlayingView.bounds];
    if (self) 
    {
        self.underlayingView = underlayingView;

        //  Create the UIView that will contain the actual keyboard
        self.innerInputView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, underlayingView.bounds.size.height)];

        //  You would need to add your custom buttons to this view; for this example, it's just red
        self.innerInputView.backgroundColor = [UIColor redColor];

        [self addSubview:self.innerInputView];
    }
    return self;
}

-(id)hitTest:(CGPoint)point withEvent:(UIEvent *)event 
{
    //  A hitTest is executed whenever the user touches this UIView or any of its subviews.

    id hitTest = [super hitTest:point withEvent:event];

    //  Since we want to ignore any clicks on the "transparent" part (this view), we execute another hitTest on the underlying view.
    if (hitTest == self)
    {
        return [self.underlayingView hitTest:point withEvent:nil];
    }

    return hitTest;
}

@end

在一些 UIViewController 中使用自定义键盘:

- (void)viewDidLoad
{
    [super viewDidLoad];

    CustomKeyboardView *customKeyboard = [[CustomKeyboardView alloc] initForUnderlayingView:self.view];
    textField.inputView = customKeyboard;
}
于 2012-05-08T00:05:48.913 回答