指定根视图

    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

最新文章

  1. mysql join 和left join 对于索引的问题
  2. C/C++: C++可调用对象详解
  3. 使用dig查询dns解析
  4. php命令行运行出现错误Call to undefined function curl_init()
  5. zabbix配置文件详解
  6. linux dmesg命令参数及用法详解(linux显示开机信息命令)
  7. 一:java概述:
  8. JAVA多线程synchronized详解
  9. hive中sql解析出对应表和字段的调查
  10. jQuery安装和基础语法
  11. HDOJ2007-平方和与立方和
  12. PyQt5--基础篇:用eric6工具实现三级联动效果
  13. Docker镜像细节
  14. robotframework在3.7下的搭建
  15. IAR FOR AVR 仿真过程中出现全局变量值不断随意变化的问题
  16. 经典文摘:饿了么的 PWA 升级实践(结合Vue.js)
  17. 嵌入式Linux驱动笔记(十八)------浅析V4L2框架之ioctl【转】
  18. 使用准现网的数据,使用本地的样式脚本,本地调试准现网页面(PC适用)
  19. Linux学习9-CentOS搭建nginx环境
  20. 【驱动】——seq_file使用指南

热门文章

  1. Cisco 关闭命令同步提示信息
  2. javascrpt_数组学习
  3. 混合式应用开发之Cordova+vue(1)
  4. python笔记六(函数的参数、返回值)
  5. 编写高性能的Lua代码
  6. Android 多窗口
  7. 最大熵模型The Maximum Entropy
  8. SpriteKit物理引擎碰撞中5个重要信息
  9. JAVA面向对象-----多态
  10. Matlab:如何查找给定目录下的文件