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=;
[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];

(ios) nsnotification总结的更多相关文章

  1. IOS NSNotification Center 通知中心的使用

    通知中心,它是IOS程序内部的一种消息广播机制,通过它,可以实现无引用关系的对象之间的通信.通知中心他是基于观察者模式,它只能进行程序内部通信,不能跨应用程序进程通信.当通知中心接受到消息后会根据设置 ...

  2. IOS NSNotification 通知

    一. 先看下官方对NSNotification通知的解释 1. NSNotification 通知 @interface NSNotification : NSObject <NSCopying ...

  3. iOS NSNotification的使用

    如果在一个类中想要执行另一个类中的方法可以使用通知 1.创建一个通知对象:使用notificationWithName:object: 或者 notificationWithName:object:u ...

  4. iOS NSNotification传递带参数的通知

    普通的通知使用 注册观察者 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getNotificat ...

  5. iOS NSNotification通知

    通知中心(NSNotificationCenter) 通知(NSNotification) 一个完整的通知一般包含3个属性:(注意顺序) - (NSString *)name;  通知的名称 - (i ...

  6. IOS中通知中心(NSNotificationCenter)

    摘要 NSNotification是IOS中一个调度消息通知的类,采用单例模式设计,在程序中实现传值.回调等地方应用很广.   IOS中通知中心NSNotificationCenter应用总结 一.了 ...

  7. ios基础篇(十八)——Delegate 、NSNotification 和 KVO用法及其区别

    一.Delegate Delegate本质是一种程序设计模型,iOS中使用Delegate主要用于两个页面之间的数据传递.iphone中常用@protocol和delegate的机制来实现接口的功能. ...

  8. ios delegate, block, NSNotification用法

    ios中实现callback可以通过两种方法,委托和NSNotification 委托的话是一对一的关系,例如一个UIViewController里有一个tableView, 将该viewContro ...

  9. iOS页面间传值的方式(NSUserDefault/Delegate/NSNotification/Block/单例)

    iOS页面间传值的方式(NSUserDefault/Delegate/NSNotification/Block/单例) 实现了以下iOS页面间传值:1.委托delegate方式:2.通知notific ...

随机推荐

  1. Tsung测试Tigase

    用两台主机坐Tigase的Tsung测试,其中1台运行Tigase,另1台运行Tsung. 1.Tigase服务器设置 tigase.conf: #osgiEnabled=(true|false) # ...

  2. ios跑酷游戏源码完整版

    今天在网上看到了一个很流行的ios游戏源码,酷跑游戏源码,个人下载感觉非常不错,运行起来非常不错的,大家可以研究一下吧,由于源码文件较大,没有上传,请大家见谅. 由于文件较大,没有上传了,大家可以到这 ...

  3. 第 23 章 CSS3 边框图片效果

    学习要点: 1.属性初探 2.属性解释 3.简写和版本 主讲教师:李炎恢 本章主要探讨 HTML5 中 CSS3 中边框图片背景的效果,通过这个新属性让边框更加的丰富多彩. 一.属性解释 CSS3 提 ...

  4. PHP curl超时问题

    今天调试一个非常老的代码时  发现nginx服务器超时  改了下nginx配置 发现是后台脚本一直等待  排查到最后发现是curl 超时引起的等待 具体解决方案: curl_setopt( $this ...

  5. Node.JS事件驱动机制

    1.事件驱动程序绑定事件及事件的处理程序 eventEmitter.on('eventName', eventHandler); 我们可以通过程序触发事件 // 触发事件 eventEmitter.e ...

  6. Hibernate(一)__简介

    一. hibernate是什么 (一)hibernate 是一个orm框架,orm (object relation mapping) 对象关系映射框架 o object -> 业务层(只对对象 ...

  7. struts—文件的上传和下载

    设计了一个小的案例:上传图片到服务器,上传成功后显示图片列表,然后点击下载上传到服务器的图片. 注意表单的配置属性: <form enctype="multipart/Form-dat ...

  8. LazyCode 自己开源的一个类库

    LazyCode 是什么? LazyCode 一个懒人用的代码类库,包括的模块:网络请求,数据存储,UIKit ,Foundation的一些类目 PHNetWorkClient 功能 1:发送GET ...

  9. Photopile JS – 帮助你实现精致的照片堆叠效果

    Photopile JS 是模拟照片散布堆叠在一起的 JavaScript/jQuery 图片库.点击缩略图,照片会弹出放大 ,再次点击照片会返回.缩略图是可拖动的,允许照片深深的堆在一起而不被覆盖, ...

  10. Plyr – 简单,灵活的 HTML5 媒体播放器

    Plyr 是一个简单的 HTML5 媒体播放器,包含自定义的控制选项和 WebVTT 字幕.它是只支持现代浏览器,轻量,方便和可定制的媒体播放器.还有的标题和屏幕阅读器的全面支持. 在线演示      ...