#import "ViewController.h"

@interface ViewController ()<UITextViewDelegate>

{

UIView *bgView;

UITextView *inputView;

CGRect keyBoardRect;

NSMutableArray *allContent;

}

@end

/*

1.NSDate 时间格式

2.NSTimeInterval 时间间隔
基本单位 秒

3.NSDateFormatter 时间格式器
用于日期对象的格式化或者字符串解析日期为对象

时间戳:

日期格式例如以下:

y  年

M  年中的月份

D  当天是今年的第多少天

d  月份中的天数

F  月份中的周数

E  星期几

a  Am/pm

H  一天中的小时数(0-23)

k  一天中的小时数(1-24)

K  am/pm 中的小时数(0-11)  Number  0

h  am/pm 中的小时数(1-12)  Number  12

m  小时中的分钟数  Number  30

s  分钟中的秒数  Number  55

S  毫秒数  Number  978

z  时区  General time zone  Pacific Standard Time; PST; GMT-08:00

Z  时区  RFC 822 time zone  -0800

4.比較时间:

(1)比較两个日期是不是同一个日期 isEqualToDate

(2)获取较早的日期 earlierDate

(3)获取较晚的时间 lateDate

(4)获取两个日期间隔多少秒

*/

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

allContent = [NSMutableArray array];

//通过通知检測键盘显示的状态

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoard:) name:UIKeyboardWillShowNotification object:nil];

[[NSNotificationCenter defaultCenter ] addObserver:self selector:@selector(keyBoard:) name:UIKeyboardWillHideNotification object:nil];

//须要输入框和其上面的button同一时候上移

bgView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetHeight(self.view.frame)-40, CGRectGetWidth(self.view.frame), 40)];

bgView.backgroundColor = [UIColor grayColor];

[self.view addSubview:bgView];

inputView = [[UITextView alloc]initWithFrame:CGRectMake(50, 5, 200, 30)];

inputView.layer.cornerRadius = 5;

inputView.delegate = self;

[bgView addSubview:inputView];

UIButton *sendBt = [UIButton buttonWithType:UIButtonTypeCustom];

sendBt.frame = CGRectMake(CGRectGetMaxX(inputView.frame)+20, 5, 80, 30);

[bgView addSubview:sendBt];

sendBt.backgroundColor = [UIColor cyanColor];

[sendBt setTitle:@"发送" forState:UIControlStateNormal ];

[sendBt setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

sendBt.tag = 100;

sendBt.layer.cornerRadius = 5;

//默认不能够使用button,输入内容后才使用

sendBt.enabled = YES;

[sendBt addTarget:self action:@selector(senContent:) forControlEvents:UIControlEventTouchUpInside];

}

#pragma ------------键盘的状态--------------

- (void)keyBoard:(NSNotification *)not

{

NSDictionary *info = not.userInfo;

//    NSLog(@"%@",info);

keyBoardRect = [info[UIKeyboardFrameEndUserInfoKey]CGRectValue];

bgView.frame = CGRectMake(0, CGRectGetMinY(keyBoardRect)-40, CGRectGetWidth(self.view.frame), 40);

}

#pragma ------------TextViewDelegate方法--------------

- (void)textViewDidBeginEditing:(UITextView *)textView

{

//開始编辑的时候
同意发送button使用

UIButton *button = (UIButton *)[bgView viewWithTag:100];

button.enabled = YES;

}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text

{

//通过检測textView输入的内容得到它的内容高度,把内容的高度设置成inputView的高度以及bgView的高度

bgView.frame = CGRectMake(0, CGRectGetHeight([UIScreen mainScreen].bounds)-textView.contentSize.height-10-CGRectGetHeight(keyBoardRect), CGRectGetWidth([UIScreen mainScreen].bounds), textView.contentSize.height+10);

inputView.frame = CGRectMake(50, 5, 200, textView.contentSize.height);

return YES;

}

#pragma ------------发送输入的内容--------------

- (void)senContent:(UIButton *)sender

{

[inputView resignFirstResponder];

NSLog(@"%@",inputView.text);

inputView.text = @"";

NSDate *curDate = [NSDate date];

NSLog(@"%@",[NSString stringWithFormat:@"%@",curDate]);

//时
分 秒

NSDateFormatter *formatter = [[NSDateFormatter alloc]init];

//设置时间格式

formatter.dateFormat = @"y/M/d E  a hh: mm :ss";

//把curDate依照时间格式
转化成字符串

NSString *time = [formatter stringFromDate:curDate];

//NSDateFormatter 转换的时间
是设备的时间

NSLog(@"%@",time);

//获得从1970年到如今的时间间隔(一般是时间戳的
时间间隔)

NSTimeInterval timeInterval = [curDate timeIntervalSince1970];

NSString *timeString = [NSString stringWithFormat:@"%0.f",timeInterval];

NSLog(@"时间戳:%@",timeString);

//把时间戳
转换成 日期

NSDate *date  = [NSDate dateWithTimeIntervalSince1970:[timeString doubleValue]];

NSLog(@"时间戳
转时间%@",[formatter stringFromDate:date]);

//获得较早的日期

//NSDate *earDate = [date earlierDate:date];

//通过时间间隔
能够计算未来+ 或者过去的时间-

//NSDate dateWithTimeIntervalSinceNow:
计算当前日期到时间间隔日期

//获得一天的时间间隔

NSTimeInterval interval = 24*60*60;

//设置时间格式为
年 月

NSDate *ysterday = [NSDate dateWithTimeIntervalSinceNow:-interval];

formatter.dateFormat = @"yyyy-MM-dd";

NSLog(@"%@",[formatter stringFromDate:ysterday]);

NSDictionary *info = @{@"content":inputView.text,@"time":time};

[allContent addObject:info];

//指定依据那个key
进行分类

NSSortDescriptor *soreDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"time" ascending:NO];

NSMutableArray *soreDescriptorArry = [NSMutableArray arrayWithObjects:&soreDescriptor count:1];

//依据
描写叙述的数组进行排序

allContent = [[allContent sortedArrayUsingDescriptors:soreDescriptorArry] mutableCopy];

sender.enabled = NO;

NSLog(@"%@",allContent);

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end


最新文章

  1. Linux系统GCC常用命令和GCC编译过程描述
  2. Python基础之反射
  3. UTC与GMT时间
  4. 【PHP开发】国外程序员收集整理的 PHP 资源大全
  5. JS网页顶部弹出可关闭广告图层
  6. android studio无法关联源码
  7. CF 500 C. New Year Book Reading 贪心 简单题
  8. POJ-2718 Smallest Difference
  9. 设计模式------STRATEGY(策略模式)
  10. 客户端(android,ios)与服务器通信
  11. POJ 2579 Fiber Network(状态压缩+Floyd)
  12. Oracle EBS-SQL (SYS-21):sys_用户名与人员对应关系查询.sql
  13. C语言学习第九章
  14. mkdir与mkdirs的区别
  15. Rational Rose 2007下载、安装和破解
  16. Python并发复习4- concurrent.futures模块(线程池和进程池)
  17. 鼠标滑过table时修改表格行的背景颜色
  18. [小技巧]diff的文件夹忽略使用方式
  19. 编写radware的负载配置
  20. 【预处理】【分类讨论】Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains

热门文章

  1. [转帖]关于flask-login中各种API使用实例
  2. Angular——自定义服务
  3. org.apache.jasper.JasperException: javax.el.PropertyNotFoundException: Property [xxx] not readable on type [xxx]
  4. MFC窗体大小变化
  5. java.lang.NoClassDefFoundError: org/hibernate/validator/internal/engine/DefaultClockProvider
  6. CAD绘制一个图象标记对象(com接口VB语言)
  7. 梦想CAD控件com接口扩展数据
  8. Mybatis逆向工程使用方法
  9. Java怎么实现文件数据拷贝
  10. extjs动态插入一列