今天的代码是在昨天的基础上完成了,昨天主要完成了QQ主界面,今天完成的主要是聊天界面

聊天界面一共有三个部分,最上面是一个导航栏NavigationBar

中间界面是一个UITableViewCell

下端界面是一个UIView,分别由TextLable和两个Button组成

在输入框时写两个,一个作为显示界面,另一个作为输出界面

//
//  Constants.h
//  QQ
//
//  Created by PXD on 15-4-29.
//  Copyright (c) 2015年 PXD. All rights reserved.
//

#ifndef QQ_Constants_h
#define QQ_Constants_h

typedef enum{
    kHeaderViewDirectionRight,
    kHeaderViewDirectionDown
}kHeaderViewDirection;

#endif

//
//  SectionHeaderView.h
//  QQ
//
//  Created by PXD on 15-4-29.
//  Copyright (c) 2015年 PXD. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "Constants.h"

@protocol SectionHeaderDirectionDelegate <NSObject>

- (void)headerViewDirectionDidChanged:(kHeaderViewDirection)direction section:(NSInteger)section;

@end

@interface SectionHeaderView : UIView

@property (nonatomic, assign) NSInteger section;
@property (nonatomic, strong) NSString *title;
@property (nonatomic, assign) kHeaderViewDirection      direction;
@property (nonatomic, assign) id<SectionHeaderDirectionDelegate> delegate;

@end

//
//  SectionHeaderView.m
//  QQ
//
//  Created by PXD on 15-4-29.
//  Copyright (c) 2015年 PXD. All rights reserved.
//

#import "SectionHeaderView.h"

@interface SectionHeaderView ()
@property (nonatomic, strong) UIImageView *directionImageView;
@property (nonatomic, strong) UILabel     *titleLabel;
@end

@implementation SectionHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        //创建按钮
        UIButton *bgButton = [UIButton buttonWithType:UIButtonTypeSystem];
        [bgButton setFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        [bgButton setBackgroundColor:[UIColor colorWithRed:226/255.0 green:242/255.0 blue:251/255.0 alpha:1]];
        [bgButton addTarget:self action:@selector(buttonDidClicked) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:bgButton];
        
        //创建剪头
        self.directionImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 12, 20, 20)];
        _directionImageView.image = [UIImage imageNamed:@"right"];
        [bgButton addSubview:_directionImageView];
        
        //创建titleLabel
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 12, 200, 20)];
        _titleLabel.text = @"绯闻女友 7/20";
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        _titleLabel.font = [UIFont systemFontOfSize:13];
        [bgButton addSubview:_titleLabel];
    }
    return self;
}

- (void)setTitle:(NSString *)title{
    if (_title != title) {
        _title = title;
    }
    
    //将文本显示到titleLabel上
    self.titleLabel.text = _title;
}

- (void)setDirection:(kHeaderViewDirection)direction{
    _direction = direction;
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    if (_direction == kHeaderViewDirectionDown) {
        //剪头向下
        self.directionImageView.transform = CGAffineTransformMakeRotation(M_PI_2);
        //self.directionImageView.transform = CGAffineTransformRotate(_directionImageView.transform, M_PI_2);
    } else{
        //剪头向右边
        self.directionImageView.transform = CGAffineTransformMakeRotation(M_PI_2 * 4);
        //self.directionImageView.transform = CGAffineTransformRotate(_directionImageView.transform, -M_PI_2);
    }
    [UIView commitAnimations];
}

- (void)buttonDidClicked{
    self.direction = (_direction == kHeaderViewDirectionDown )? kHeaderViewDirectionRight : kHeaderViewDirectionDown;
    
    //将当前的状态回调给viewController
    if([_delegate respondsToSelector:@selector(headerViewDirectionDidChanged:section:)]){
        [_delegate headerViewDirectionDidChanged:_direction section:_section];
    }
}
@end

//
//  ChatViewController.h
//  QQ
//
//  Created by PXD on 15-4-29.
//  Copyright (c) 2015年 PXD. All rights reserved.
//

#import <UIKit/UIKit.h>

@class FriendsModel;//前向声明
@interface ChatViewController : UIViewController<UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate>

- (instancetype)initWithNibName:(NSString *)nibNameOrNil
                         bundle:(NSBundle *)nibBundleOrNil
                    friendModel:(FriendsModel *)model;
@end

//
//  ChatViewController.m
//  QQ
//
//  Created by PXD on 15-4-29.
//  Copyright (c) 2015年 PXD. All rights reserved.
//

#import "ChatViewController.h"
#import "FriendsModel.h"

@interface ChatViewController ()
@property (nonatomic, strong) FriendsModel *model;
@property (nonatomic, strong) UITableView *myTableView;
@property (nonatomic, strong) UITextField *inputTextField;
@property (nonatomic, strong) UITextField *showingTextField;
@end

@implementation ChatViewController
- (instancetype)initWithNibName:(NSString *)nibNameOrNil
                         bundle:(NSBundle *)nibBundleOrNil
                    friendModel:(FriendsModel *)model{
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        self.model = model;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self uiInitial];
    
    //注册(监听)一个键盘弹出来的消息
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardShow:) name:UIKeyboardDidShowNotification object:nil];
    
    //注册(监听)一个键盘隐藏的消息
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardHidden:) name:UIKeyboardDidHideNotification object:nil];
}

- (void)keyboardShow:(NSNotification *)notifi{
    //让inputTextField 作为第一响应者
    [_inputTextField becomeFirstResponder];
    
    //tableView上移
    self.myTableView.frame = CGRectMake(0, 20 + 44, 320, 568 - 253 - 44 - 64);
    
    //显示最后一行
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:29 inSection:0];
    [self.myTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}

- (void)keyboardHidden:(NSNotification *)notifi{
    //将输入框的内容 显示到 showingTextField上
    _showingTextField.text = _inputTextField.text;
    
    //tableView还原
    self.myTableView.frame = CGRectMake(0, 64, 320, 568-64-44);
}

- (void)uiInitial{
    UIImage *bgImage = [UIImage imageNamed:@"bg"];
    UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
    bgImageView.image = bgImage;
    [self.view addSubview:bgImageView];
    
    self.myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, 320, 568-64-44) style:UITableViewStylePlain];
    _myTableView.delegate = self;
    _myTableView.dataSource =self;
    _myTableView.backgroundColor = [UIColor clearColor];
    _myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_myTableView];
    
    //真正的输入视图
    UIView *reallyInputOperationView = [self createMessageInputOperationView];
    reallyInputOperationView.frame = CGRectMake(0, 0, 320, 44);
    
    self.inputTextField = [[UITextField alloc]initWithFrame:CGRectMake(30, 10, 200, 24)];
    _inputTextField.placeholder = @"message";
    _inputTextField.borderStyle = UITextBorderStyleLine;
    _inputTextField.delegate = self;
    [reallyInputOperationView addSubview:_inputTextField];
    
    //显示的输入视图
    UIView *showingOperationView = [self createMessageInputOperationView];
    [self.view addSubview:showingOperationView];
    
    self.showingTextField = [[UITextField alloc]initWithFrame:CGRectMake(30, 10, 200, 24)];
    _showingTextField.placeholder = @"message";
    _showingTextField.borderStyle = UITextBorderStyleLine;
    _showingTextField.inputAccessoryView = reallyInputOperationView;
    [showingOperationView addSubview:_showingTextField];
}

- (void)setModel:(FriendsModel *)model{
    if (_model != model) {
        _model  = model;
    }
    //设置导航栏的标题 为联系人的名字
    self.title = _model.friendName;
}

#pragma mark -- TableDelegate&DataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 30;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"cellID";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    cell.backgroundColor = [UIColor clearColor];
    cell.textLabel.text = [NSString stringWithFormat:@"row_%ld", indexPath.row];
    return cell;
}

- (UIView *)createMessageInputOperationView{
    //背景视图
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 568-44, 320, 44)];
    [bgView setBackgroundColor:[UIColor lightTextColor]];
    
    //笑脸
    UIButton *faceButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [faceButton setFrame:CGRectMake(240, 7, 30, 30)];
    [faceButton setBackgroundImage:[UIImage imageNamed:@"face"] forState:UIControlStateNormal];
    [bgView addSubview:faceButton];
    
    //add
    UIButton *addButton = [UIButton buttonWithType:UIButtonTypeContactAdd];
    [addButton setFrame:CGRectMake(280, 7, 30, 30)];
    [bgView addSubview:addButton];
    
    return bgView;
}

#pragma mark -- UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    //取消textfield的第一响应者
    [_inputTextField resignFirstResponder];
    [_showingTextField resignFirstResponder];
    
    return YES;
}

#pragma mark -- UIScrollViewDelegate
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    //取消textfield的第一响应者
    [_inputTextField resignFirstResponder];
    [_showingTextField resignFirstResponder];
}
@end

day 026 QQ相关推荐

  1. Entity FrameWork中常用的数据修改方式

    http://buluo.qq.com/p/detail.html?bid=392683&pid=1192374-1505239292&2017.09.13/o936=dl http: ...

  2. 移动简报026—智慧餐厅出新服务:吃饭用微信就可排队;支付宝上线银行卡安全险:盗刷最高获赔 50 万;高德正式发布车载导航App...

    移动简报026 [移动营销] 艾瑞:2015年中国移动广告市场规模突破900亿 2015年移动广告市场规模达到901.3亿元,同比增长率高达178.3%,发展势头十分强劲.移动广告的整体市场增速远远高 ...

  3. php使用qq登录api接口,QQ的账号登录及PHP api操作

    QQ的账号登录及api操作,使用oauth 2.0官方提供的sdk都太过庞大,这是我自己简化的,提供简单的账号登录.获取个人信息.发布分享等功能,如果需要其他功能可以根据官方的api文档自行添加[文件 ...

  4. 100条超搞笑的“雷人”QQ/MSN 签名

    100条超搞笑的"雷人"QQ/MSN 签名 001 - 老鼠一发威,大家都是病猫. 002 - 和一MM争论鲸鱼是不是鱼,最后我说"曰本人也带个人字",她这才同 ...

  5. 王者荣耀微信哪个服务器人多,明明是用微信的比用QQ的多,那为何王者荣耀QQ区人更多?...

    王者荣耀登录分为微信登录和QQ登录,很容易想象现在人们的主要沟通工具就是微信了,QQ已经不常用了,而王者荣耀又是一个注重团队的游戏,自然而然都想和好友一起排位了.所以大部分人玩的都是微信区,当然不包括 ...

  6. QQ的账号登录及PHP api操作

    QQ的账号登录及api操作,使用oauth 2.0     官方提供的sdk都太过庞大,这是我自己简化的,提供简单的账号登录.获取个人信息.发布分享等功能,如果需要其他功能可以根据官方的api文档自行 ...

  7. QQ协议分析之TCPF包数据分析

    2019独角兽企业重金招聘Python工程师标准>>> QQ协议分析之TCPF包数据分析 博客分类: 抓包 说明: 本文档说明的是解密以后的TCPF数据包的字段内容.有关如何解密,请 ...

  8. 使用第三方SDK(如微信、qq、快看、头条等),调用接口405 Method Not Allowed

    使用第三方SDK(如微信.qq.快看.头条等),调用接口405 Method Not Allowed 错误描述:postman请求正常,但客户端调用后接口没有反应,但返回了405错误. 解决方法:第三 ...

  9. python3:利用SMTP协议发送QQ邮件+附件

    转载请表明出处:https://www.cnblogs.com/shapeL/p/9115887.html 1.发送QQ邮件,首先必须知道QQ邮箱的SMTP服务器 http://service.mai ...

最新文章

  1. 雷达篇(九)雷达中的“快采样”和“慢采样”
  2. android studio配置java_android studio配置Javah 和ndk-build
  3. 【OpenCV 例程200篇】59. 非线性滤波—双边滤波
  4. ​​2021快手母婴行业数据价值报告
  5. python字符串匹配的准确率_说说在 Python 中,如何找出所有字符串匹配
  6. 让计算机启动更快的十五招
  7. DOCTYPE用法详解
  8. redis设计与实现 二
  9. ORACLE安装之环境搭建
  10. 嵌入式Linux应用开发完全手册 pdf 韦东山
  11. 常用的十大塑料成型工艺(优缺点介绍)
  12. android 面试题(史上最全)
  13. 电商APP首页楼层架构设计详解
  14. MACD指标为什么不灵了?试试QMACD
  15. **Python 复数计算会丢失虚部的问题**ComplexWarning: Casting complex values to real discards the imaginary part
  16. (HDOJ)Vowel Counting-Java实现
  17. Gank教学贴:Gank是一门艺术 不是固定的套路
  18. 基于SSM企业生产计划管理系统
  19. 前端如何通过vue/cli脚手架创建vue项目
  20. 分享一些实用的软件工具

热门文章

  1. 计算机专业人才面试小结
  2. 手机红灯闪烁,但是无法开机
  3. 新必应newBing申请攻略
  4. 简单计算机唱歌教学,【Da老师】最简单详细的唱歌基础教程
  5. YESLAB老余——网络自动化系列(2)
  6. JAVA的 IO/NIO 从生瓜蛋子到大头兵
  7. 解决cron不执行的问题
  8. 学习笔记(02):Python自动化测试九章经(仅视频课-unittest基础之fixture
  9. Bingo说说:如何在互联网上快速赚到钱?答案有点扎心
  10. pyecharts桑基图制作遇到的问题