iOS horizontal screen to get keyboard height 0, keyboard side eject problem

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.