How to make an individual keyboard undocking?

Like iOS 5, the iPad keyboard can undock / split.

But my user keyboard cannot detach when my application is first launched. Only after, say, a warning is displayed and rejected, does the keyboard become detachable.

I created 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 testing steps are as follows:

  • Launch the app.
  • Click on the editor and the keyboard will show.
  • Make sure you cannot move the keyboard by dragging its lower right corner.
  • Press the editor again, the keyboard will be hidden, and a warning window will appear.
  • Disable the warning view.
  • The third time, click the editor and the keyboard will show.
  • Make sure that you can now move the keyboard by dragging its lower right corner.

Done.

I wonder how to make the keyboard loose at the very beginning after launch. Any information appreciated!

+4
source share

Source: https://habr.com/ru/post/1495350/


All Articles