さて、私はこの質問を投稿する前にまともなゴーグルをしましたが、正しい答えを見つけることができませんでした. 説明が少し複雑なので、ここでアプリのシナリオ全体を説明することはできません。ですから、この質問を非常に簡単にさせてください。UIKeyBoard
.ieのフレームを変更するにはどうすればよいですか? ビューの位置をサポートするために、 UIKeyBoard を上向きに 90 度回転または移動させたいです。私に抜け道はありますか?
2168 次
1 に答える
4
デフォルトのキーボードを変更することはできません。inputView
ただし、 UITextFieldなどのように設定することで、キーボードの代替として使用するカスタムUIViewを作成できます。
カスタムキーボードの作成には少し時間がかかりますが、古いバージョンのiOS(inputView
UITextFieldではiOS 3.2以降で使用可能)でうまく機能し、物理キーボードをサポートします(キーボードが接続されている場合は自動的に非表示になります)。
垂直キーボードを作成するためのサンプルコードを次に示します。
インターフェース:
#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 に答える