day 028 qq输入框加载FaceView

//
//  FaceView.m
//  QQ
//
//  Created by PXD on 15-5-3.
//  Copyright (c) 2015ๅนด PXD. All rights reserved.
//


#import "FaceView.h"


@interface FaceView ()
@property (nonatomic, strong) UIScrollView *faceScrollView;
@end


@implementation FaceView


- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
//        self.faceScrollView = [[UIScrollView alloc] initWithFrame:frame];
//        _faceScrollView.backgroundColor = [UIColor lightGrayColor];
//        [self addSubview:_faceScrollView];
    }
    return self;
}


@end


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


#import "ChatViewController.h"
#import "FriendsModel.h"
#import "FaceView.h"
#import "AppDelegate.h"


typedef enum {
    kFaceButtonStatusFace = 1,
    kFaceButtonStatusKeyboard
}kFaceButtonStatus;


@interface ChatViewController ()
@property (nonatomic, strong) FriendsModel *model;
@property (nonatomic, strong) UITableView *myTableView;
@property (nonatomic, strong) UITextField *inputTextField;
@property (nonatomic, strong) UITextField *showingTextField;
@property (nonatomic, strong) FaceView *faceView;
@property (nonatomic, strong) UIView *showingOperationView;
@property (nonatomic, strong) UIView *reallyInputOperationView;
@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];
    
    //真正的输入视图
    self.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];
    
    //显示的输入视图
    self.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];
    [faceButton addTarget:self action:@selector(faceButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside];
    faceButton.tag = kFaceButtonStatusKeyboard;
    [bgView addSubview:faceButton];
    
    //add
    UIButton *addButton = [UIButton buttonWithType:UIButtonTypeContactAdd];
    [addButton setFrame:CGRectMake(280, 7, 30, 30)];
    [bgView addSubview:addButton];
    
    return bgView;
}


//重写faceView的get方法
- (FaceView *)faceView{
    if (_faceView == nil) {
        _faceView = [[FaceView alloc] initWithFrame:CGRectMake(0, 568-253, 320, 253)];
        _faceView.hidden = YES;
        _faceView.backgroundColor = [UIColor redColor];
        [self.view addSubview:_faceView];
    }
    return _faceView;
}


#pragma mark -- FaceButtonAction
- (void)faceButtonDidClicked:(UIButton *)sender{
    if (sender.tag == kFaceButtonStatusKeyboard) {
        //显示表情视图
        self.faceView.hidden = NO;
        //改变button的状态
        sender.tag = kFaceButtonStatusFace;
        
        self.showingOperationView.frame = CGRectMake(0, 568-253-44, 320, 44);
        
        UIButton *showViewButton = (UIButton *)[self.showingOperationView viewWithTag:kFaceButtonStatusKeyboard];
        showViewButton.tag = kFaceButtonStatusFace;
        
        [self.inputTextField resignFirstResponder];
        [self.showingTextField resignFirstResponder];
        
        
    } else {
        //隐藏表情视图
        self.faceView.hidden = YES;
        
        sender.tag = kFaceButtonStatusKeyboard;
        
        [_showingTextField becomeFirstResponder];
        
        self.showingOperationView.frame = CGRectMake(0, 568-44, 320, 44);
        
        UIButton *reallyViewButton = (UIButton *)[self.reallyInputOperationView viewWithTag:kFaceButtonStatusFace];
        reallyViewButton.tag = kFaceButtonStatusKeyboard;
    }
}


#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
























1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值