[IOS] using notifications to implement a listening system keyboard

Source: Internet
Author: User

////VIEWCONTROLLER.M//text////Created by LDW on 16/1/22.//copyright©2016 year LDW. All rights reserved.//#import<UIKit/UIKit.h>#import "ViewController.h"@interfaceViewcontroller ()@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; Uitextview*TEXTV =[[Uitextview alloc] initWithFrame:self.view.bounds];        [Self.view ADDSUBVIEW:TEXTV]; //1. Add Notifications    [[Nsnotificationcenter defaultcenter] addobserver:self selector: @selector (keyboardchange:) Name:    Uikeyboardwillshownotification Object:nil]; //keyboard will appear uikeyboardwillshownotification//keyboard has appeared uikeyboarddidshownotification//The keyboard will be hidden uikeyboardwillhidenotification//Keyboard has been hidden uikeyboarddidhidenotification    }//2. The keyboard has been triggered by a call- (void) Keyboardchange: (Nsnotification *) noti{NSLog (@"%@", Noti);//Print Noti    /*0x7f84584d1000 {name = uikeyboarddidshownotification; userInfo = {//Keyboard animation performs rhythm Uikeyboardanimationcurveuserinf     Okey = 7;     Keyboard animation Time Uikeyboardanimationdurationuserinfokey = "0.25";     Keyboard bounds Uikeyboardboundsuserinfokey = "Nsrect: {{0, 0}, {375, 258}}";     Keyboard Start Center Uikeyboardcenterbeginuserinfokey = "Nspoint: {187.5, 796}";     End of Keyboard Center Uikeyboardcenterenduserinfokey = "Nspoint: {187.5, 538}";     The position before the keyboard begins the animation (that is, when it disappears) Uikeyboardframebeginuserinfokey = "Nsrect: {{0, 667}, {375, 258}}";     The position after the keyboard finishes the animation (that is, it pops up) Uikeyboardframeenduserinfokey = "Nsrect: {{0, 409}, {375, 258}}";     Uikeyboardislocaluserinfokey = 1; }}     */        //3. So how do you get this value?   nsdictionary *nokey = [Noti userInfo];    Nsvalue *value = nokey[@ "Uikeyboardboundsuserinfokey"]; //Note that this value is of type CGRect (so the Cgrectvalue method must be called below )    NSLog (@ "%f" , [value cgrectvalue].size.height]; }@end

There are errors also forget you pointed out, if this article help you, or you have any suggestions and additions, can leave a message to tell me Oh!

[IOS] using notifications to implement a listening system keyboard

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.