iOS horizontal screen to get keyboard height 0, keyboard side eject problem
In the video screen at the time, often appear the keyboard bug, roughly divided into two kinds:
1, Horizontal screen state of the keyboard from the home key direction pop-up
2, get the keyboard height will sometimes appear as 0 of the situation
Note: You can use the Iqkeyboardmanager framework to import projects. And do not need to calculate the keyboard height to change the position of the input box, screen content will automatically move up, very easy to use. (If you need a horizontal screen operation, you also need to do the following methods)
below to achieve horizontal screen, and does not appear above the keyboard bug:
1. Set the View controller-based status bar appearance to No in Info.plist file
After this setting, you want to change the status bar color and hide so write it
[UIApplication sharedapplication].statusbarstyle = uistatusbarstylelightcontent;
[UIApplication Sharedapplication].statusbarhidden = YES;
2,
Tick the direction you want to rotate.
3, in their own written navigationcontroller and Tabbarcontroller inside, respectively, write the following code
1, Navigationcontroller Inside:
-(BOOL) shouldautorotate{return
self.topViewController.shouldAutorotate;
-(Uiinterfaceorientationmask) supportedinterfaceorientations
{
return Uiinterfaceorientationmasklandscaperight | uiinterfaceorientationmaskportrait;
}
-(uiinterfaceorientation) preferredinterfaceorientationforpresentation{return
uiinterfaceorientationportrait;
}
2, Tabbarcontroller Inside:
-(BOOL) shouldautorotate{return
self.selectedViewController.shouldAutorotate;
-(uiinterfaceorientationmask) supportedinterfaceorientations
{return
Uiinterfaceorientationmasklandscaperight | uiinterfaceorientationmaskportrait;
}
-(uiinterfaceorientation) preferredinterfaceorientationforpresentation{return
uiinterfaceorientationportrait;
}
4, in the need to do the rotation operation of the controller to write the following code:
-(BOOL) shouldautorotate
{return
YES;
}
-(Uiinterfaceorientationmask) supportedinterfaceorientations{return
uiinterfaceorientationmaskportrait | Uiinterfaceorientationmasklandscape;
}
-(uiinterfaceorientation) preferredinterfaceorientationforpresentation{return
uiinterfaceorientationportrait | Uiinterfaceorientationlandscaperight;
}
5, the selection of the screen method code
SEL selector = nsselectorfromstring (@ "setorientation:");
Nsinvocation *invocation = [Nsinvocation invocationwithmethodsignature:[uidevice instancemethodsignatureforselector : selector]];
[Invocation setselector:selector];
[Invocation Settarget:[uidevice Currentdevice]];
int val = uiinterfaceorientationlandscaperight;//direction of rotation
[invocation setargument:&val atindex:2];
[Invocation invoke];
According to the above steps, in the horizontal screen state, keyboard pop-up will not appear abnormal, get the keyboard height will also be normal
The interface UI adjusts itself to make the horizontal screen and vertical screen judgment.