iOS中 通知中心Text (实例)

简介:

[objc]  view plain  copy
  1.   
指定根视图

[objc]  view plain  copy
  1. self.window.rootViewController = [RootViewController new];  

方法实现:

[objc]  view plain  copy
  1. #import "RootViewController.h"  
  2. #define kScreenHeight [UIScreen mainScreen].bounds.size.height  
  3. #define kScreenWidth [UIScreen mainScreen].bounds.size.width  
  4. @interface RootViewController ()  
  5. @property (nonatomicstrongUITextField *textField;  
  6. @end  
  7. @implementation RootViewController  
  8.   
  9. - (void)viewDidLoad  
  10. {  
  11.     [super viewDidLoad];  
  12.       
  13.     self.view.backgroundColor = [UIColor greenColor];  
  14.       
  15.     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeFrame:) name:UIKeyboardWillShowNotification object:nil];  
  16.     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hiddenFrame2:) name:UIKeyboardWillHideNotification object:nil];  
  17.       
  18.     self.textField = [[UITextField alloc] initWithFrame:CGRectMake(50, kScreenHeight - 100, kScreenWidth - 10035)];  
  19.     self.textField.borderStyle = UITextBorderStyleRoundedRect;  
  20.     [self.view addSubview:self.textField];  
  21. }  


[objc]  view plain  copy
  1. - (void)changeFrame:(NSNotification *)sender  
  2. {  
  3.     CGRect frame = self.textField.frame;  
  4.     frame.origin.y = 100;  
  5.     [UIView animateWithDuration:2 animations:^{  
  6.         self.textField.frame = frame;  
  7.     }];  
  8. }  
  9.   
  10. - (void)hiddenFrame2:(NSNotification *)sender  
  11. {  
  12.     [UIView animateWithDuration:2 animations:^{  
  13.         CGRect frame = self.textField.frame;  
  14.         frame.origin.y = kScreenHeight - 100;  
  15.   
  16.         self.textField.frame = frame;  
  17.     }];  
  18. }  


释放:

[objc]  view plain  copy
  1. - (void)dealloc  
  2. {  
  3.     [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];  
  4.     [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];  
  5. }  

最终效果:



有问题可以关注我微博私信我.http://weibo.com/hanjunqiang



原文地址:http://blog.csdn.net/qq_31810357/article/details/49611281
相关文章
|
开发工具 C++ iOS开发
iOS ipa包瘦身,iOS8及以下text段超60MB
前沿很早之前写过一篇相关文章,不过博客主机上跑路了之后数据没了,凭着记忆补了下相关资料 ipa安装包瘦身清理无用图片,图片压缩(PNG换WebP和JPG),处于某种不可抗拒的原因,导致有部分3X图没有被App Thining处理,这部分3x图是否可以删除只用2x图。
1464 0
|
iOS开发
iOS中 通知中心Text (实例)
指定根视图 self.window.rootViewController = [RootViewController new]; 方法实现: #import "RootViewController.
546 0
|
1月前
|
API 数据安全/隐私保护 iOS开发
利用uni-app 开发的iOS app 发布到App Store全流程
利用uni-app 开发的iOS app 发布到App Store全流程
88 3
|
3月前
|
存储 iOS开发
iOS 开发,如何进行应用的本地化(Localization)?
iOS 开发,如何进行应用的本地化(Localization)?
122 2
|
3月前
|
存储 数据建模 数据库
IOS开发数据存储:什么是 UserDefaults?有哪些替代方案?
IOS开发数据存储:什么是 UserDefaults?有哪些替代方案?
39 0
|
3月前
|
安全 编译器 Swift
IOS开发基础知识: 对比 Swift 和 Objective-C 的优缺点。
IOS开发基础知识: 对比 Swift 和 Objective-C 的优缺点。
93 2
|
3月前
|
API 开发工具 iOS开发
iOS 开发高效率工具包:10 大必备工具
iOS 开发高效率工具包:10 大必备工具
48 1
|
3月前
|
API 数据安全/隐私保护 iOS开发
利用uni-app 开发的iOS app 发布到App Store全流程
利用uni-app 开发的iOS app 发布到App Store全流程
54 1
|
8天前
|
API 定位技术 iOS开发
IOS开发基础知识:什么是 Cocoa Touch?它在 iOS 开发中的作用是什么?
【4月更文挑战第18天】**Cocoa Touch** 是iOS和Mac OS X应用的核心框架,包含面向对象库、运行时系统和触摸优化工具。它提供Mac验证的开发模式,强调触控接口和性能,涵盖3D图形、音频、网络及设备访问API,如相机和GPS。是构建高效iOS应用的基础,对开发者至关重要。
12 0