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. 其实Unix很简单

    很多编程的朋友都在网上问我这样的几个问题,Unix怎么学?Unix怎么这么难?如何才能学好?并且让我给他们一些学好Unix的经验.在绝大多数时候,我发现问这些问题的朋友都有两个特点: 1)对Unix有 ...

  2. SQL(触发器)

    触发器语法格式(实例): ALTER TRIGGER tri_edituserON dbo.sys_UserFOR INSERT,UPDATE,DELETEAS BEGIN ---判断是新增?修改?删 ...

  3. 【Java每日一题】20161014

    20161013问题解析请点击今日问题下方的"[Java每日一题]20161014"查看 package Oct2016; import java.util.Arrays; imp ...

  4. mysql数据过滤

    WHERE子句 在我们使用数据库时,通常只会根据特定条件提取表数据的子集.只检索所需数据需要指定搜索条件(search criteria),搜索条件也称为过滤条件(filtercondition). ...

  5. spring MVC @Resource不支持Lazy加载

    今天迁一系统时发现有个bean使用@Resource注入了另外一个bean,这个被注入的bean是将被deprecated的类,而且只有一两个功能使用到,为了先调整进行测试,增加了@Lazy注解,启动 ...

  6. Java基础学习总结--对象容器

    目录: ArrayList 顺序泛型容器 HashSet 集合容器 HashMap<Key,Value>容器 要用Java实现记事本的功能.首先列出记事本所需功能: 可以添加记录(字符串) ...

  7. 一道js面试题

     当然这道面试题并不一定就能在你面试的时候遇到,但是不怕一万就怕万一,会的多一些还是好的. 问:怎么判断一串字符中哪个字符出现的最多,最多几次或者这串字符分别有哪些,每个字符出现了几次.写你请出运算代 ...

  8. Code First :使用Entity. Framework编程(1) ----转发 收藏

    这个是在学习EF CodeFirst时发现的,对于初学者还是不错的.果断转发,方便自己以后查阅和学习. 对于学习Code First 这个教程讲解的还是很详细. 第一章:欢迎来到Code First ...

  9. Pexels Videos – 可以免费商业使用的短视频

    Pexels 是一个巨大的平台,提供免费的精美照片,很多设计师和博客每天用它来寻找他们的个人和商业项目的照片.现在我们想介绍 Pexels 视频,他是用来帮助你找到免费的视频.所有的 Pexels 视 ...

  10. sharepoint多个NLB的web前段如何进行文件同步?

    大家都知道,sharepoint2010服务器场可能有2个或2个以上的web服务器做NLB,有个时候牵涉到上传文件到文件夹(说到这里,有人会说全部以二进制文件保存到文档库啊,但是有些情况不允许的,比如 ...