Just started to do iOS, do not good, but also hope that friends a lot of advice, thank you!
#import "ViewController.h"@interfaceViewcontroller () <UITextFieldDelegate>{UIView*ActiveView; Uitextfield*TextField; floatKeyboardheight; floatW, H;}@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; W=Self.view.bounds.size.width; H=Self.view.bounds.size.height; Self.view.backgroundColor=[Uicolor Whitecolor]; ActiveView= [[UIView alloc] Initwithframe:cgrectmake (0, H- +W $)]; Activeview.backgroundcolor= [Uicolor colorwithred:0.4Green0.3Blue0.5Alpha1.0]; [Self.view Addsubview:activeview]; TextField= [[Uitextfield alloc] Initwithframe:cgrectmake (Ten,Ten, W -, -)]; Textfield.backgroundcolor=[Uicolor Lightgraycolor]; Textfield.keyboardappearance=Uitextborderstyleroundedrect; TextField.Delegate=Self ; [ActiveView Addsubview:textfield]; [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (keyboardwillappear:) Name: UikeyboardwillshownotificationObject: nil];}-(BOOL) textfieldshouldbeginediting: (Uitextfield *) textfield{[[Nsnotificationcenter Defaultcenter] Postnotificationname:uikeyboardwillshownotificationObject: nil]; returnYES;}- (void) Keyboardwillappear: (nsnotification*) noti{nsdictionary*keybinfo =[Noti UserInfo]; Nsvalue*value =[Keybinfo Objectforkey:uikeyboardframeenduserinfokey]; CGRect Keyboardframe=[value cgrectvalue]; Keyboardheight=KeyboardFrame.size.height; [UIView animatewithduration:1animations:^{cgrect Tframe=Activeview.frame; TFRAME.ORIGIN.Y= H-keyboardheight- +; Activeview.frame=Tframe; }];}- (void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Uievent *)Event{[TextField resignfirstresponder]; [UIView animatewithduration:0.3animations:^{cgrect Tframe=Activeview.frame; TFRAME.ORIGIN.Y= h- +; Activeview.frame=Tframe; }];}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}@end
iOS keyboard popup text input box Move up