2012-05-04 36 views
7

Vâng, tôi đã trải qua một số goggling khá trước khi gửi câu hỏi này nhưng đã không thành công trong việc tìm kiếm câu trả lời đúng. Tôi không thể giải thích toàn bộ kịch bản ứng dụng của mình ở đây vì nó phức tạp một chút để giải thích. Vì vậy, hãy để tôi làm cho câu hỏi này rất đơn giản. Làm cách nào tôi có thể thay đổi khung của UIKeyBoard .i.e. Tôi muốn UIKeyBoard xoay hoặc dịch 90 độ trở lên để hỗ trợ vị trí xem của tôi. Có cách nào giúp tôi không?Làm thế nào để thay đổi khung của UIKeyBoard lập trình trong iOS

+0

Trong ios5 điều đó có sẵn.kiểm tra trong wwdc2011. – vishiphone

+0

im nghĩa vụ phải hỗ trợ tất cả các thiết bị với ios 4.2 trở lên: ( –

+0

Nhưng tôi nghĩ đó là phức tạp hơn Buddy tôi không biết về điều này xin lỗi – vishiphone

Trả lời

4

Bạn không thể thay đổi bàn phím mặc định. Tuy nhiên, bạn có thể tạo UIView tùy chỉnh để sử dụng làm bàn phím thay thế bằng cách đặt nó là inputView trên, ví dụ: UITextField.

Trong khi tạo bàn phím tùy chỉnh mất một chút thời gian, nó hoạt động tốt với các phiên bản iOS cũ hơn (inputView trên UITextField có sẵn trong iOS 3.2 trở lên) và hỗ trợ bàn phím vật lý (bàn phím được ẩn tự động nếu bàn phím được kết nối) .

Dưới đây là một số mẫu mã để tạo ra một bàn phím dọc:

Interface:

#import <UIKit/UIKit.h> 

@interface CustomKeyboardView : UIView 

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

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

@end 

Thực hiện:

#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 

Sử dụng bàn phím tùy chỉnh trong một số UIViewController:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    CustomKeyboardView *customKeyboard = [[CustomKeyboardView alloc] initForUnderlayingView:self.view]; 
    textField.inputView = customKeyboard; 
} 
+0

Âm thanh tuyệt vời .. Hãy để tôi thử điều này ... BTW +1 :) –

Các vấn đề liên quan