国产探花免费观看_亚洲丰满少妇自慰呻吟_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];

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 朝阳市| 临江市| 大新县| 中牟县| 延安市| 宁晋县| 武定县| 福清市| 呼图壁县| 西和县| 肥东县| 兴山县| 夏津县| 资兴市| 蓬溪县| 堆龙德庆县| 聊城市| 忻州市| 南充市| 嘉义市| 广丰县| 台北市| 浮山县| 筠连县| 德阳市| 紫金县| 子洲县| 双江| 滦南县| 北安市| 黑山县| 北川| 花莲市| 德保县| 土默特左旗| 元江| 清徐县| 永春县| 吉首市| 平度市| 江西省|