黑马程序员IOS键盘的关闭以及通知中心的运用
来源:互联网 发布:盐城seo 编辑:程序博客网 时间:2024/06/05 18:40
------Java培训、Android培训、iOS培训、.Net培训、期待与您交流! -------
</pre><pre code_snippet_id="523183" snippet_file_name="blog_20141117_2_4904939" name="code" class="objc">#import <UIKit/UIKit.h>@interface ViewController : UIViewController<UITextFieldDelegate,UITextViewDelegate>@end
#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad { NSLog(@"哈哈"); [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib.}- (void)viewWillAppear:(BOOL)animated{ //注册键盘出现通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keybardDidShow:) name:UIKeyboardDidShowNotification object:nil]; //注册键盘隐藏通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keybardHidShow:) name:UIKeyboardDidHideNotification object:nil]; [super viewWillAppear:animated];}- (void)viewDidDisappear:(BOOL)animated{ //解除通知 [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidShowNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidHideNotification object:nil];}-(void)keybardDidShow:(NSNotification *)notif{ NSLog(@"键盘打开");}-(void)keybardHidShow:(NSNotification *)notif{ NSLog(@"键盘关闭");}#pragma mark - UITextField Delegate Method//分类宏- (BOOL)textFieldShouldReturn:(UITextField *)textField{ [textField resignFirstResponder]; return YES;}#pragma mark - UITextField Delegate Method-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{ if ([text isEqualToString:@"\n"]) { [textView resignFirstResponder]; return NO; } return YES;}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
本代码是基于拖放控件来实现
键盘不能关闭的原因是需要这些控件来放弃第一响应者的身份,需要调用UIResponder类中resignFirstResponder方法,可以通过return和点击背景处罚,但是本方法是采用点击return来关闭
0 0
- 黑马程序员IOS键盘的关闭以及通知中心的运用
- IOS的通知中心
- 键盘的关闭打开通知
- iOS打开和关闭键盘的通知使用
- IOS键盘通知中心方法
- iOS 通知中心的使用
- iOS 的通知中心简介
- iOS通知中心的使用
- iOS键盘的关闭
- iOS 系统 键盘的通知
- 关闭和打开键盘的通知
- 关闭和打开键盘的通知
- 关闭和打开键盘的通知
- 获取应用在ios系统通知中心的设置?开启:关闭
- 关于IOS键盘遮住输入框以及关闭的方法。
- iOS通知中心的简单实现-YRSignal
- IOS NSNotification Center 通知中心的使用
- iOS通知中心的使用流程
- 文本分类实验中用java实现取名词和去除停用词
- awk中next以及getline用法示例
- C++ 静态变量或成员初始化陷阱与缺陷
- UVA 401 Palindromes 回文词
- 使用greenDAO进行开发总结
- 黑马程序员IOS键盘的关闭以及通知中心的运用
- Fedora 17 修改GRUB启动菜单顺序
- NYOJ-49 开心的小明
- Titanium笔记---ScrollableView
- 设计模式之(Decorator)装饰者模式
- poj 1681 Painter's Problem 高斯消元
- IplImage和Mat的转换
- 二进制与java移位
- IIS Web服务扩展中添加ASP.NET4.0