iOS中 通知中心Text (实例)
2015-11-03 08:24
369 查看
指定根视图
方法实现:
释放:
最终效果:
![](http://img.blog.csdn.net/20151103082916519)
有问题可以关注我微博私信我.http://weibo.com/hanjunqiang
self.window.rootViewController = [RootViewController new];
方法实现:
#import "RootViewController.h" #define kScreenHeight [UIScreen mainScreen].bounds.size.height #define kScreenWidth [UIScreen mainScreen].bounds.size.width @interface RootViewController () @property (nonatomic, strong) UITextField *textField; @end @implementation RootViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor greenColor]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeFrame:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hiddenFrame2:) name:UIKeyboardWillHideNotification object:nil]; self.textField = [[UITextField alloc] initWithFrame:CGRectMake(50, kScreenHeight - 100, kScreenWidth - 100, 35)]; self.textField.borderStyle = UITextBorderStyleRoundedRect; [self.view addSubview:self.textField]; }
- (void)changeFrame:(NSNotification *)sender { CGRect frame = self.textField.frame; frame.origin.y = 100; [UIView animateWithDuration:2 animations:^{ self.textField.frame = frame; }]; } - (void)hiddenFrame2:(NSNotification *)sender { [UIView animateWithDuration:2 animations:^{ CGRect frame = self.textField.frame; frame.origin.y = kScreenHeight - 100; self.textField.frame = frame; }]; }
释放:
- (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; }
最终效果:
有问题可以关注我微博私信我.http://weibo.com/hanjunqiang
相关文章推荐
- iOS中大流中的自定义cell 技术分享
- iOS中大流中的自定义cell 技术分享
- ios消息队列APNS实现和证书申请
- IOS中NSUserDefaults的用法(轻量级本地数据存储)
- 蓝懿ios 技术内容和心得交流分享 11.2 打飞机主要步骤
- iOS数据持久化之归档
- iOS MBProgressHUD 的使用方法
- iOS 多线程
- iOS地图分析
- CoreData(1)
- iOS学习必备的7个开源项目
- iOS多线程GCD
- ios调用web service
- iOS资源图片命名注意事项
- iOS模拟器上home键调用方法(2种)
- iOS CoreData之单表操作(增删改查)
- IOS中获取各种文件的目录路径
- 关于字典转模型的一些思考(持续更新中)
- IOS项目笔记-1
- 阿健的iOS开发Demo(加法计算器、图片浏览(动画))