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. iOS阶段学习第15天笔记(NSDate操作)

    iOS学习(OC语言)知识点整理 一.OC关于NSDate类的操作实例代码 //默认直接显示对象,显示的是格林威治时间 //获取当前日期时间的实例方法 NSDate *date1=[[NSDate a ...

  2. 走进异步世界:EnyimMemcached异步化改造引起的内存泄漏

    6月30日我们发布了异步化改造后的博客程序之后,出现了高内存.高CPU.高线程数的不理想情况. 经过一周的追查,终于水落日出——引起不理想情况的根源是我们修改过的EnyimMemcached代码存在内 ...

  3. Xamarin.ios——First APP

    环境:MAC+Xamarin Studio 先讲讲安装吧,最普遍的方法就是去Xamarin官网,注册个账号,填写信息啥的开始下载,安装.但,在天朝的网络环境下,在下载android模块的东东时,总会下 ...

  4. jquery基本选择器匹配多个元素

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. 【Java每日一题】20161109

    package Nov2016; import java.lang.reflect.Method; public class Ques1109 { public static void main(St ...

  6. SNAT,是源地址转换,其作用是将ip数据包的源地址转换成另外一个地址

    SNAT,可能有人觉得奇怪,好好的为什么要进行ip地址转换啊,为了弄懂这个问题,我们要看一下局域网用户上公网的原理,假设内网主机A(192.168.2.8)要和外网主机B(61.132.62.131) ...

  7. 几个最常用的Mysql命令

    shell>mysql -u用户名 -p密码 mysql>show databases; mysql>use 数据库名称; mysql>show tables; mysql&g ...

  8. IOS 2D游戏开发框架 SpriteKit-->续(postion,锚点,游戏滚动场景)

    一. Postion 这里的postion和app开发中的layer.postion是一样的,postion的值代表该视图在父节点中的相对位置, 比如一个试图的父节点是self.view, 这里我们想 ...

  9. Scalaz(32)- Free :lift - Monad生产线

    在前面的讨论里我们提到自由数据结构就是产生某种类型的最简化结构,比如:free monoid, free monad, free category等等.我们也证明了List[A]是个free mono ...

  10. [python拾遗]异常处理

    异常 异常(Exception)是因为程序的例外.违例.出错等情况而在正常控制流以外采取的行为,一般分为如下两个阶段: 1.异常发生:一个错误发生后被打印出来,称为未处理异常,而默认的处理则是自动输出 ...