国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

(ios)nsnotification總結

2019-11-14 20:43:51
字體:
來源:轉載
供稿:網友

1  文本輸入,鍵盤顯示時,view向上,鍵盤隱藏時,view向下

1.1 注冊鍵盤顯示,關閉通知,并實現主界面上下變動

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];}-(void)keyboardWillShow:(NSNotification *)aNotification{    CGRect keyBoardRect=[[[aNotification userInfo]objectForKey:UIKeyboardFrameBeginUserInfoKey]CGRectValue];        NSTimeInterval animalInterval=[[[aNotification userInfo]objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];    CGRect frame=self.view.frame;    frame.origin.y=-keyBoardRect.size.height;    [UIView beginAnimations:@"keyboardshow" context:nil];    [UIView setAnimationDuration:animalInterval];    self.view.frame=frame;    [UIView commitAnimations];}-(void)keyboardWillHide:(NSNotification *)aNotification{    NSTimeInterval animalInterval=[[[aNotification userInfo]objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];    CGRect frame=self.view.frame;    frame.origin.y=0;    [UIView beginAnimations:@"keyboardhide" context:nil];    [UIView setAnimationDuration:animalInterval];    self.view.frame=frame;    [UIView commitAnimations];    }

1.2 文本框初始化,并實現UITextViewDelegate委托

    self.textbox.returnKeyType=UIReturnKeyDone;    self.textbox.delegate=self;} - (BOOL)textFieldShouldReturn:(UITextView *)textView{ [textView resignFirstResponder];    return YES;}

 

2 自定義notification

 2.1 定義偵聽自定義notification觀察者

//注冊觀察者,偵聽自定義通知    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(selfNotificationDO:) name:@"CustomNotification" object:nil];}-(void)selfNotificationDO:(NSNotification *)aNotification{     //處理notification    //........}

2.2 生成一個自定義notification

//生成一個自定義Notification    [[NSNotificationCenter defaultCenter] postNotificationName:@"CustomNotification" object:self];

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 娄底市| 上犹县| 云浮市| 原平市| 泗阳县| 万州区| 绍兴市| 萍乡市| 垫江县| 宁乡县| 班玛县| 西平县| 广汉市| 衡山县| 图木舒克市| 长顺县| 梓潼县| 革吉县| 宁波市| 石渠县| 景谷| 余江县| 滨州市| 丁青县| 射阳县| 龙岩市| 福清市| 齐河县| 青田县| 乌拉特后旗| 沾化县| 大化| 武胜县| 海丰县| 莱阳市| 射洪县| 安塞县| 乌拉特中旗| 登封市| 商河县| 昌黎县|