As of iOS 5, iPad keyboard can undock/split.
But my custom keyboard can not undock when my app is first launched. Only after, say, an alert view is shown and dismissed, the keyboard becomes undock-able.
I made a test project based on the Single View Application template as follows:
MyViewController.m :
#import "MyViewController.h"
#import "MyEditor.h"
@implementation MyViewController
- (void)viewDidLoad {
[super viewDidLoad];
MyEditor *editor = [[MyEditor alloc] initWithFrame:CGRectMake(0, 640, 768, 100)];
editor.backgroundColor = [UIColor cyanColor];
[self.view addSubview:editor];
}
@end
MyEditor.m :
#import "MyEditor.h"
#import "MyKeyboard.h"
@implementation MyEditor
- (CGSize)intrinsicContentSize {
return CGSizeMake(UIViewNoIntrinsicMetric, 100);
}
- (UIView *)inputView {
return [MyKeyboard sharedKeyboard];
}
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if ([self isFirstResponder]) {
[self resignFirstResponder];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:nil delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alertView show];
}
else {
[self becomeFirstResponder];
}
}
@end
MyKeyboard.m :
#import "MyKeyboard.h"
@implementation MyKeyboard
+ (MyKeyboard *)sharedKeyboard {
static MyKeyboard *sharedKeyboard;
if (sharedKeyboard == nil) {
sharedKeyboard = [[MyKeyboard alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
}
return sharedKeyboard;
}
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[super setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
[super setBackgroundColor:[UIColor yellowColor]];
}
return self;
}
@end
The test steps are as follows:
- Launch the app.
- Tap the editor, and the keyboard will show.
- Verify that you can not move the keyboard by dragging the lower-right corner of it.
- Tap the editor again, the keyboard will hide, and an alert view will show.
- Dismiss the alert view.
- Tap the editor a third time, and the keyboard will show.
- Verify that now you can move the keyboard by dragging the lower-right corner of it.
Done.
I wonder how to make the keyboard undock-able at the very beginning after launch. Any info is appreciated!