(ios) nsnotification总结
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总结的更多相关文章
- IOS NSNotification Center 通知中心的使用
通知中心,它是IOS程序内部的一种消息广播机制,通过它,可以实现无引用关系的对象之间的通信.通知中心他是基于观察者模式,它只能进行程序内部通信,不能跨应用程序进程通信.当通知中心接受到消息后会根据设置 ...
- IOS NSNotification 通知
一. 先看下官方对NSNotification通知的解释 1. NSNotification 通知 @interface NSNotification : NSObject <NSCopying ...
- iOS NSNotification的使用
如果在一个类中想要执行另一个类中的方法可以使用通知 1.创建一个通知对象:使用notificationWithName:object: 或者 notificationWithName:object:u ...
- iOS NSNotification传递带参数的通知
普通的通知使用 注册观察者 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getNotificat ...
- iOS NSNotification通知
通知中心(NSNotificationCenter) 通知(NSNotification) 一个完整的通知一般包含3个属性:(注意顺序) - (NSString *)name; 通知的名称 - (i ...
- IOS中通知中心(NSNotificationCenter)
摘要 NSNotification是IOS中一个调度消息通知的类,采用单例模式设计,在程序中实现传值.回调等地方应用很广. IOS中通知中心NSNotificationCenter应用总结 一.了 ...
- ios基础篇(十八)——Delegate 、NSNotification 和 KVO用法及其区别
一.Delegate Delegate本质是一种程序设计模型,iOS中使用Delegate主要用于两个页面之间的数据传递.iphone中常用@protocol和delegate的机制来实现接口的功能. ...
- ios delegate, block, NSNotification用法
ios中实现callback可以通过两种方法,委托和NSNotification 委托的话是一对一的关系,例如一个UIViewController里有一个tableView, 将该viewContro ...
- iOS页面间传值的方式(NSUserDefault/Delegate/NSNotification/Block/单例)
iOS页面间传值的方式(NSUserDefault/Delegate/NSNotification/Block/单例) 实现了以下iOS页面间传值:1.委托delegate方式:2.通知notific ...
随机推荐
- Delegate
public delegate void EventHandler(object sender, EventArgs e); pulic EventHandler HandleMapMessage; ...
- js Date 时间格式化的扩展
js Date 时间格式化的扩展: Date.prototype.format = function (fmt) { var o = { , //月 "d+": this.getD ...
- hhvm的正确安装姿势 http://dl.hhvm.com 镜像
hhvm是php的第三方运行环境,由facebook出品,基于该运行环境,它还提供了一种编程语言hack - PHP的静态类型版. 折腾了一天后,包括各种编译.配置.FQ,后面终于忍不住搜了一下 ht ...
- swipe.js 2.0 轻量级框架实现mobile web 左右滑动
属性总结笔记如下: <style> .swipe { overflow: hidden; //隐藏溢出 清楚浮动 visibility: hidden; //规定元素不可见 (可以设置,当 ...
- PhantomJS快速入门
本文简要介绍了PhantomJS的相关基础知识点,主要包括PhantomJS的介绍.下载与安装.HelloWorld程序.核心模块介绍等.由于鄙人才疏学浅,难免有疏漏之处,欢迎指正交流. 1.Phan ...
- jquery多次上传同一张图片
$().reset(); wrap():$('p').wrap('div');===><div><p></p></div>; .closest() ...
- HTML5 Canvas 高仿逼真 3D 布料图案效果
HTML5 规范引进了很多新特性,其中最令人期待的之一就是 Canvas 元素,HTML5 Canvas 提供了通过 JavaScript 绘制图形的方法,非常强大.下面给大家分享一个 HTML5 C ...
- aBowman >>可以运用到自己博客上的小插件
大家进入我的博客会发现页面右边有一只小狗这部分.这个就是我用在上面的 一个小插件.插件网址是:http://abowman.com/google-modules/,这上面有很多的小插件,可以直接运用到 ...
- JavaScript中with语句的理解
with语句的作用是暂时改变作用域链.减少的重复输入. 其语法结构为: with(object){ //statements } 举一个实际例子吧: with(document.forms[0]){ ...
- CSS3 一、文本阴影text-shadow属性
文本阴影text-shadow属性特效: 1.右下角阴影,左下角阴影,左上角阴影,右上角阴影 <!DOCTYPE html> <html lang="en"> ...