iOS Development-Auto-hide keyboard and status bar

Source: Internet
Author: User

1. Hide the status bar

After iOS upgraded to 7.0, many APIs were abolished, and the original method of hiding the status bar StatusBar was invalidated.

Original plan

[[UIApplication sharedapplication] setstatusbarhidden:yes];
Unfortunately, it worked in later versions, so we can use the new API to implement the purpose of the hidden State column, as follows:
-(BOOL) prefersstatusbarhidden{    return YES;

2. Automatically hide the keyboard and automatically layout

The solution provided here is suitable for any type of keyboard, mainly considering that Numberpad has no return key.

It is also a scheme based on Scrollerview for layout, using the animated effect of Scrollerview.

The code is as follows:

@implementation testviewcontroller-(void) viewdidload {    [super viewdidload];    Do any additional setup after loading the view.    [_scrollview Addgesturerecognizer:[[uitapgesturerecognizer alloc] initwithtarget:self action: @selector ( Hidekeyboard)]];} -(void) textfielddidbeginediting: (Uitextfield *) textfield{    //keyboard height is 216    [_scrollview setframe:cgrectmake (0, 0, _scrollview.frame.size.width, _scrollview.frame.size.height+216)];    [_scrollview setcontentoffset:cgpointmake (0) animated:yes];    [_scrollview settag:0];    } -(void) hidekeyboard{    if (_scrollview.tag==0) {        [_scrollview setcontentoffset:cgpointmake (0, 0) animated:yes ];        [_scrollview setframe:cgrectmake (0, 0, _scrollview.frame.size.width, _scrollview.frame.size.height-216)];        [Self.view Endediting:yes];        [_scrollview settag:1];}}}    

iOS Development-Auto-hide keyboard and status bar

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.