add flying commit
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// GiGaFlingCommitVC.h
|
||||
// GIGA
|
||||
//
|
||||
// Created by lianxiang on 2018/8/28.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface GiGaFlingCommitVC : UIViewController
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,98 @@
|
||||
//
|
||||
// GiGaFlingCommitVC.m
|
||||
// GIGA
|
||||
//
|
||||
// Created by lianxiang on 2018/8/28.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import "GiGaFlingCommitVC.h"
|
||||
#import "GiGaFlyingCommitInputView.h"
|
||||
#import "LXDanMuManager.h"
|
||||
#import "GiGaCommentView.h"
|
||||
#import "GiGaCommentModel.h"
|
||||
#import "LXDanMuManagerConfig.h"
|
||||
#import "IQKeyboardManager.h"
|
||||
|
||||
//弹幕控制器
|
||||
@interface GiGaFlingCommitVC ()
|
||||
@property (nonatomic,strong) GiGaFlyingCommitInputView *commitInputView;
|
||||
|
||||
@end
|
||||
|
||||
@implementation GiGaFlingCommitVC
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
// Do any additional setup after loading the view.
|
||||
NC_ADD_TARGET_NAME_OBJECT(self, @selector(maskTimeEnd), kUserNoti_MASKEND, nil);
|
||||
[self.view addSubview: self.commitInputView];
|
||||
self.commitInputView.SendCommentHandler = ^(NSString *content) {
|
||||
GILog(@"发送->:%@",content);
|
||||
};
|
||||
[[LXDanMuManager shareInstance] createDanmuWithTrackSpeedArray:@[@1.00,@1.00,@3.00,@4.00] centerY:self.view.frame.size.height / 4 trackWidth:self.view.frame.size.width showInView:self.view];
|
||||
[[LXDanMuManager shareInstance] start];
|
||||
|
||||
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(danmuAction) userInfo:nil repeats:YES];
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(void)danmuAction{
|
||||
|
||||
[self showFlyingCommit];
|
||||
}
|
||||
|
||||
- (GiGaFlyingCommitInputView *)commitInputView{
|
||||
|
||||
if (!_commitInputView) {
|
||||
// _commitInputView = [[GiGaFlyingCommitInputView alloc] initWithFrame:CGRectMake(0,self.view.frame.size.height - 60 , KMainW, 60)];
|
||||
_commitInputView = [[GiGaFlyingCommitInputView alloc] initWithFrame:self.view.bounds];
|
||||
[_commitInputView setPalceholderText:@"请输入弹幕"];
|
||||
}
|
||||
return _commitInputView;
|
||||
}
|
||||
-(void)viewWillAppear:(BOOL)animated{
|
||||
[super viewWillAppear:animated];
|
||||
[IQKeyboardManager sharedManager].enable = NO;
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated{
|
||||
[super viewWillDisappear:animated];
|
||||
[IQKeyboardManager sharedManager].enable = YES;
|
||||
}
|
||||
|
||||
-(void)showFlyingCommit{
|
||||
NSArray *classArray = @[@"GiGaCommentView",@"GiGaCommentView"];
|
||||
NSArray *nameArray = @[@"mc子龙",@"小明",@"赵四",@"狂小狗",@"葬爱"];
|
||||
NSArray *msgArray = @[@"老铁666",@"主播,多少礼物给卡黄啊?",@"文明观球,大家有秩序排队观看,不要着急",@"主播,我报警啦",@"就是个萨比,还扮滴酷酷滴aaaaa"];
|
||||
NSArray *avatarArray = @[@"home_login_qq_color",@"home_login_qq_color",@"home_login_qq_color",@"home_login_qq_color",@"home_login_qq_color"];
|
||||
int classRandomIndex = arc4random() % 2;
|
||||
int nameRandomIndex = arc4random() % 5;
|
||||
int msgRandomIndex = arc4random() % 5;
|
||||
int avatarRandomIndex = arc4random() % 5;
|
||||
|
||||
GiGaCommentModel *model = [[GiGaCommentModel alloc]init];
|
||||
model.userName = nameArray[nameRandomIndex];
|
||||
model.msg = msgArray[msgRandomIndex];
|
||||
model.userAvatar = avatarArray[avatarRandomIndex];
|
||||
GiGaCommentView *customView = [[NSClassFromString(classArray[classRandomIndex]) alloc] initWithMsgModel:model height:TRACK_HEIGHT];
|
||||
[[LXDanMuManager shareInstance] appendDanMuWithCustomView:customView toTrackIndex:-1];
|
||||
}
|
||||
|
||||
-(void)maskTimeEnd{
|
||||
|
||||
[[LXDanMuManager shareInstance] destory];
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[super didReceiveMemoryWarning];
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
-(void)dealloc{
|
||||
NC_REMOVE_NAME(self, kUserNoti_MASKEND, nil);
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -23,28 +23,70 @@
|
||||
#import "GiGaHelper.h"
|
||||
#import <MediaPlayer/MediaPlayer.h>
|
||||
#import "GiGaMeViewController.h"
|
||||
|
||||
@interface GiGaMaskTaskViewController ()
|
||||
#import "GiGaFlyingCommitInputView.h"
|
||||
#import "GiGaFlingCommitVC.h"
|
||||
@interface GiGaMaskTaskViewController ()<UITextFieldDelegate>
|
||||
{
|
||||
AVAudioPlayer *_musicPalyer;
|
||||
}
|
||||
@property(nonatomic,strong)MaskViewBootomWaringView *waringView;
|
||||
@property(nonatomic,strong)UILabel *countLabel;
|
||||
@property (strong ,nonatomic) LXCountTimer *timer;
|
||||
//@property (nonatomic,strong) GiGaFlyingCommitInputView *commitInputView;
|
||||
@property(nonatomic,strong) UIImageView *maskImageView;
|
||||
@property(nonatomic,strong) UIImageView *faceView;
|
||||
@property(nonatomic,strong) UIDynamicAnimator *animator;
|
||||
@property(nonatomic,strong) UIAttachmentBehavior *attachmentBehavior;
|
||||
@property(nonatomic) CGPoint attachPoint;
|
||||
@property(nonatomic) UISnapBehavior *snapBehavior;
|
||||
|
||||
@end
|
||||
|
||||
@implementation GiGaMaskTaskViewController
|
||||
|
||||
//倒计时label
|
||||
-(UILabel *)countLabel{
|
||||
if (!_countLabel) {
|
||||
_countLabel = [[UILabel alloc] init];
|
||||
_countLabel.textColor = [UIColor redColor];
|
||||
_countLabel.text = @"30:00";
|
||||
_countLabel.text = @"00:00";
|
||||
_countLabel.textAlignment = NSTextAlignmentCenter;
|
||||
|
||||
}
|
||||
return _countLabel;
|
||||
}
|
||||
//面膜
|
||||
- (UIImageView *)maskImageView{
|
||||
if (!_maskImageView) {
|
||||
_maskImageView = [[UIImageView alloc] init];
|
||||
_maskImageView.userInteractionEnabled = YES;
|
||||
_maskImageView.backgroundColor = [UIColor purpleColor];
|
||||
UIPanGestureRecognizer *pangesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureAction:)];
|
||||
[_maskImageView addGestureRecognizer:pangesture];
|
||||
}
|
||||
return _maskImageView;
|
||||
}
|
||||
//人脸
|
||||
- (UIImageView *)faceView{
|
||||
if (!_faceView) {
|
||||
_faceView = [[UIImageView alloc] init];
|
||||
_faceView.backgroundColor = [UIColor lightGrayColor];
|
||||
_faceView.userInteractionEnabled = YES;
|
||||
}
|
||||
return _faceView;
|
||||
}
|
||||
|
||||
-(void)createInputView{
|
||||
|
||||
GiGaFlingCommitVC* GiGaFlingVC = [[GiGaFlingCommitVC alloc] init];
|
||||
if (ISIOS8) {
|
||||
GiGaFlingVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
|
||||
}else{
|
||||
GiGaFlingVC.modalPresentationStyle = UIModalPresentationCurrentContext;
|
||||
}
|
||||
GiGaFlingVC.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
|
||||
[self presentViewController:GiGaFlingVC animated:NO completion:nil];
|
||||
|
||||
}
|
||||
|
||||
-(LXCountTimer *)timer{
|
||||
@@ -55,6 +97,73 @@
|
||||
return _timer;
|
||||
}
|
||||
|
||||
//滑动手势
|
||||
-(void)panGestureAction:(UIPanGestureRecognizer *)pan{
|
||||
|
||||
CGPoint panLocation = [pan locationInView:self.view];
|
||||
NSLog(@"panlocation.y:%f",panLocation.y);
|
||||
if (pan.state == UIGestureRecognizerStateBegan) {
|
||||
|
||||
[self animaMask];
|
||||
// self.attachmentBehavior = [[UIAttachmentBehavior alloc] initWithItem:self.faceView attachedToAnchor:self.attachPoint];
|
||||
// [self.animator addBehavior: self.attachmentBehavior ];
|
||||
|
||||
}else if (pan.state == UIGestureRecognizerStateChanged){
|
||||
// [self.snapBehavior setSnapPoint:self.attachPoint];
|
||||
// [self.attachmentBehavior setAnchorPoint:panLocation];
|
||||
|
||||
}else if (pan.state == UIGestureRecognizerStateEnded){
|
||||
// [self.animator addBehavior:self.snapBehavior];
|
||||
// [self.animator removeBehavior:self.attachmentBehavior];
|
||||
}else{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark -开始面膜时间动画
|
||||
-(void)animaMask{
|
||||
|
||||
[self.view layoutIfNeeded];
|
||||
[UIView animateWithDuration:1.0 animations:^{
|
||||
[self.maskImageView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self.attachPoint.y - 50);
|
||||
}];
|
||||
[self.faceView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self.attachPoint.y - 50);
|
||||
}];
|
||||
[self.countLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self.attachPoint.y + 50 + 10);
|
||||
}];
|
||||
[self.view layoutIfNeeded];
|
||||
} completion:^(BOOL finished) {
|
||||
self.countLabel.hidden = NO;
|
||||
self.maskImageView.userInteractionEnabled = NO;
|
||||
//开始面膜时间
|
||||
[self startMaskTime];
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark 面膜时间结束复原动画
|
||||
-(void)endMaskAnimation{
|
||||
|
||||
self.countLabel.hidden = YES;
|
||||
[self.view layoutIfNeeded];
|
||||
[UIView animateWithDuration:1.0 animations:^{
|
||||
[self.maskImageView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(100 + 100 + 200);
|
||||
}];
|
||||
|
||||
[self.faceView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(100);
|
||||
}];
|
||||
|
||||
[self.view layoutIfNeeded];
|
||||
|
||||
} completion:^(BOOL finished) {
|
||||
self.maskImageView.userInteractionEnabled = YES;
|
||||
}];
|
||||
}
|
||||
|
||||
-(void)viewWillAppear:(BOOL)animated{
|
||||
[super viewWillAppear:animated];
|
||||
|
||||
@@ -71,16 +180,37 @@
|
||||
|
||||
-(void)initUI{
|
||||
|
||||
[self.view addSubview:self.maskImageView];
|
||||
[self.view addSubview:self.faceView];
|
||||
[self.view bringSubviewToFront:self.maskImageView];
|
||||
[self.view addSubview:self.countLabel];
|
||||
|
||||
[self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self.view.mas_top).offset(200);
|
||||
make.width.mas_equalTo(100);
|
||||
make.height.mas_equalTo(30);
|
||||
make.centerX.mas_equalTo(self.view.mas_centerX);
|
||||
self.animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
|
||||
|
||||
//face
|
||||
[self.faceView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self.view.mas_top).offset(100);
|
||||
make.left.mas_equalTo(self.view.mas_centerX).offset(-50);
|
||||
make.size.mas_equalTo(CGSizeMake(100, 100));
|
||||
|
||||
}];
|
||||
|
||||
//mask
|
||||
[self.maskImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
|
||||
make.top.mas_equalTo(self.view.mas_top).offset(100 + 100 + 200);
|
||||
make.left.mas_equalTo(self.view.mas_centerX).offset(-50);
|
||||
make.size.mas_equalTo(CGSizeMake(100, 100));
|
||||
|
||||
}];
|
||||
|
||||
[self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self.view.mas_top).offset(200);
|
||||
make.width.and.height.mas_equalTo(100);
|
||||
make.centerX.mas_equalTo(self.view.mas_centerX);
|
||||
}];
|
||||
self.countLabel.hidden = YES;
|
||||
|
||||
UIButton *testBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[testBtn setTitle:@"测试肤质" forState:UIControlStateNormal];
|
||||
[testBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||||
@@ -94,8 +224,15 @@
|
||||
make.centerX.mas_equalTo(self.view.mas_centerX);
|
||||
make.width.mas_equalTo(150);
|
||||
make.height.mas_equalTo(40);
|
||||
make.bottom.mas_equalTo(self.view.mas_bottom).offset(-200);
|
||||
make.bottom.mas_equalTo(self.view.mas_bottom).offset(-130);
|
||||
}];
|
||||
|
||||
[self.view layoutIfNeeded];
|
||||
CGFloat Y = CGRectGetMinY(self.maskImageView.frame) - 100;
|
||||
CGFloat X = CGRectGetMidX(self.view.frame);
|
||||
CGPoint anchorPoint = CGPointMake(X, Y);
|
||||
self.attachPoint = anchorPoint;
|
||||
// self.snapBehavior = [[UISnapBehavior alloc] initWithItem:self.maskImageView snapToPoint:self.attachPoint];
|
||||
}
|
||||
|
||||
#pragma mark 开始计时
|
||||
@@ -131,14 +268,12 @@
|
||||
//设置后台模式和锁屏模式下依然能够播放
|
||||
//[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];
|
||||
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#pragma mark 开始面膜时间
|
||||
-(void)startMaskTime{
|
||||
|
||||
[self createInputView]; //出现弹幕
|
||||
AppDelegate *delegate =(AppDelegate *) [[UIApplication sharedApplication] delegate];
|
||||
if (delegate.isMasking) {
|
||||
return;
|
||||
@@ -148,7 +283,7 @@
|
||||
[self setBackGroundPlayingInfo];//锁屏音频信息
|
||||
|
||||
//总时间隔 s
|
||||
NSTimeInterval timeInterVal = 58;
|
||||
NSTimeInterval timeInterVal = 61;
|
||||
NSString *timeformat = [GiGaHelper stringWithNSTimerinterval:timeInterVal];
|
||||
NSArray *timesArr = [timeformat componentsSeparatedByString:@":"];
|
||||
NSString *hour = timesArr[0];
|
||||
@@ -158,6 +293,7 @@
|
||||
|
||||
[self showWaringView];
|
||||
|
||||
return;
|
||||
//app 前台时收到本地通知showAlert 后台时通知提醒
|
||||
[[GiGaLocalNotificationManager localNotifiationCenter] sendLocalNotification:@"本地推送" fireTimeInterval:timeInterVal alertAction:@"测试面膜时间" withIdentifier:kLOCALNotifiID_MASKETIMEEND];
|
||||
|
||||
@@ -183,7 +319,7 @@
|
||||
|
||||
}
|
||||
|
||||
- (void) remoteControlReceivedWithEvent: (UIEvent *) receivedEvent {
|
||||
- (void)remoteControlReceivedWithEvent: (UIEvent *) receivedEvent {
|
||||
|
||||
if (receivedEvent.type == UIEventTypeRemoteControl) {
|
||||
switch (receivedEvent.subtype) {
|
||||
@@ -207,20 +343,22 @@
|
||||
#pragma mark 面膜时间结束
|
||||
-(void)maskTimeEnd{
|
||||
|
||||
NC_POST_NAME_OBJECT(kUserNoti_MASKEND, nil);
|
||||
//面膜时间结束时设置 全局变量 不再发送本地通知 提醒
|
||||
AppDelegate *delegate =(AppDelegate *) [[UIApplication sharedApplication] delegate];
|
||||
delegate.isMasking = NO;
|
||||
[_musicPalyer stop];
|
||||
[self.timer destoryTimer];
|
||||
|
||||
//复原动画
|
||||
[self endMaskAnimation];
|
||||
}
|
||||
|
||||
#pragma mark 开始测试
|
||||
-(void)testBtnAcion:(UIButton *)btn{
|
||||
|
||||
|
||||
[self startMaskTime];
|
||||
return ;
|
||||
// [self startMaskTime];
|
||||
// return ;
|
||||
|
||||
BOOL isUserLogin = [GiGaUserDefault isUserLogin];
|
||||
|
||||
@@ -305,7 +443,6 @@
|
||||
|
||||
#pragma mark - setUpNav
|
||||
-(void)setUpNav{
|
||||
|
||||
//leftItem
|
||||
UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
leftBtn.frame = CGRectMake(0, 0, 40, 40);
|
||||
@@ -381,5 +518,4 @@
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// GiGaCommentModel.h
|
||||
// LXAnimationTest
|
||||
//
|
||||
// Created by lianxiang on 2018/8/14.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "JSONModel.h"
|
||||
@interface GiGaCommentModel :JSONModel
|
||||
|
||||
@property (nonatomic,copy) NSString *userName;
|
||||
@property (nonatomic,copy) NSString *userLevel;
|
||||
@property (nonatomic,copy) NSString *msg;
|
||||
@property (nonatomic,copy) NSString *userAvatar;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// GiGaCommentModel.m
|
||||
// LXAnimationTest
|
||||
//
|
||||
// Created by lianxiang on 2018/8/14.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import "GiGaCommentModel.h"
|
||||
|
||||
@implementation GiGaCommentModel
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// GiGaCommentView.h
|
||||
// LXAnimationTest
|
||||
//
|
||||
// Created by lianxiang on 2018/8/14.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "GiGaCommentModel.h"
|
||||
@interface GiGaCommentView : UIView
|
||||
@property(nonatomic,strong) GiGaCommentModel *msgModel;
|
||||
-(instancetype)initWithMsgModel:(GiGaCommentModel *)model height:(CGFloat)height;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,94 @@
|
||||
//
|
||||
// GiGaCommentView.m
|
||||
// LXAnimationTest
|
||||
//
|
||||
// Created by lianxiang on 2018/8/14.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import "GiGaCommentView.h"
|
||||
#import "Masonry.h"
|
||||
@interface GiGaCommentView()
|
||||
@property(nonatomic,strong) UILabel *userName;
|
||||
@property(nonatomic,strong) UIImageView *userAvtar;
|
||||
@property(nonatomic,strong) UILabel *msg;
|
||||
@end
|
||||
|
||||
@implementation GiGaCommentView
|
||||
|
||||
-(instancetype)initWithMsgModel:(GiGaCommentModel *)model height:(CGFloat)height{
|
||||
|
||||
if (self = [super init]) {
|
||||
self.frame = CGRectMake(0, 0, 0, height);
|
||||
_msgModel = model;
|
||||
//self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.5];
|
||||
self.backgroundColor = [UIColor redColor];
|
||||
[self initUI];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)layoutIfNeeded{
|
||||
|
||||
}
|
||||
- (void)layoutSubviews{
|
||||
|
||||
}
|
||||
|
||||
-(void)initUI{
|
||||
|
||||
UIImageView *avatar = [[UIImageView alloc] init];
|
||||
avatar.image = [UIImage imageNamed:@"home_login_qq_color"];
|
||||
//avatar.frame = CGRectMake(3, 3, self.frame.size.height - 6, self.frame.size.height - 6);
|
||||
avatar.layer.masksToBounds = YES;
|
||||
avatar.layer.cornerRadius = 15;
|
||||
[self addSubview:avatar];
|
||||
avatar.image = [UIImage imageNamed:_msgModel.userAvatar];
|
||||
self.userAvtar = avatar;
|
||||
[self.userAvtar mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo(30);
|
||||
make.height.mas_equalTo(30);
|
||||
make.left.mas_equalTo(self.mas_left).mas_offset(3);
|
||||
make.top.mas_equalTo(self.mas_top).mas_offset(3);
|
||||
|
||||
}];
|
||||
|
||||
UILabel *namelabel = [[UILabel alloc] init];
|
||||
namelabel.font = [UIFont systemFontOfSize:14];
|
||||
namelabel.textColor = [UIColor blackColor];
|
||||
//namelabel.frame= CGRectMake(CGRectGetMaxX(avatar.frame) + 5, 4, namelabel.frame.size.width, namelabel.frame.size.height);
|
||||
namelabel.text = _msgModel.userName;
|
||||
[namelabel sizeToFit];
|
||||
self.userName = namelabel;
|
||||
[self addSubview:self.userName];
|
||||
[self.userName mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
|
||||
make.left.mas_equalTo(self.userAvtar.mas_right).mas_offset(3);
|
||||
make.top.mas_equalTo(self.mas_top).mas_offset(10);
|
||||
|
||||
}];
|
||||
|
||||
UILabel *msglabel = [[UILabel alloc] init];
|
||||
msglabel.font = [UIFont systemFontOfSize:13];
|
||||
msglabel.textColor = [UIColor blackColor];
|
||||
|
||||
//msglabel.frame= CGRectMake(namelabel.frame.origin.x, CGRectGetMaxY(avatar.frame) - msglabel.frame.size.height - namelabel.frame.origin.y, msglabel.frame.size.width, msglabel.frame.size.height);
|
||||
msglabel.text = _msgModel.msg;
|
||||
self.msg = msglabel;
|
||||
[msglabel sizeToFit];
|
||||
[self addSubview:self.msg];
|
||||
[self.msg mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
|
||||
make.top.mas_equalTo(self.userAvtar.mas_bottom).mas_offset(3);
|
||||
make.left.mas_equalTo(self.mas_left).mas_offset(5);
|
||||
|
||||
|
||||
}];
|
||||
|
||||
float width = msglabel.frame.size.width > namelabel.frame.size.width ? msglabel.frame.size.width:namelabel.frame.size.width ;
|
||||
|
||||
self.frame = CGRectMake(0, 0, namelabel.frame.origin.x + 10 + width, self.frame.size.height);
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// GiGaFlyingCommitInputView.h
|
||||
// GIGA
|
||||
//
|
||||
// Created by lianxiang on 2018/8/28.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface GiGaFlyingCommitInputView : UIView
|
||||
|
||||
@property (nonatomic, copy) void (^SendCommentHandler)(NSString *content);
|
||||
@property (nonatomic, copy) NSString *palceholderText;
|
||||
-(void)setPalceholderText:(NSString *)palceholderText;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,169 @@
|
||||
//
|
||||
// GiGaFlyingCommitInputView.m
|
||||
// GIGA
|
||||
//
|
||||
// Created by lianxiang on 2018/8/28.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import "GiGaFlyingCommitInputView.h"
|
||||
@interface GiGaFlyingCommitInputView()<UITextFieldDelegate>
|
||||
@property(nonatomic,strong) UIView *commitInputView;
|
||||
@property(nonatomic,strong) UITextField * inputTextField;
|
||||
@end
|
||||
|
||||
@implementation GiGaFlyingCommitInputView
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
|
||||
// self.backgroundColor = [UIColor blackColor];
|
||||
self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
|
||||
// UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissSelfViewTap)];
|
||||
// [self addGestureRecognizer:tap];
|
||||
|
||||
[self creatInputView];
|
||||
[self bringSubviewToFront:_commitInputView];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)creatInputView{
|
||||
|
||||
UIView *commitView =[[UIView alloc] initWithFrame:CGRectMake(0, self.bounds.size.height - 60, self.bounds.size.width, 60)];
|
||||
// commitView.frame = CGRectMake(0, self.frame.size.height-commitView.frame.size.height, self.frame.size.width, commitView.frame.size.height);
|
||||
self.commitInputView = commitView;
|
||||
self.commitInputView.backgroundColor = [UIColor redColor];
|
||||
[self addSubview:self.commitInputView];
|
||||
|
||||
UIButton *sendBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
CGFloat topMargin = 5;
|
||||
CGFloat leftMargin = 10;
|
||||
sendBtn.frame = CGRectMake(self.frame.size.width - leftMargin - 60,topMargin,60,40);
|
||||
[sendBtn addTarget:self action:@selector(sendBtnAction:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[sendBtn setTitle:@"发送" forState:UIControlStateNormal];
|
||||
[sendBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||||
sendBtn.backgroundColor = [UIColor purpleColor];
|
||||
sendBtn.layer.masksToBounds = YES;
|
||||
sendBtn.layer.cornerRadius = 4;
|
||||
[commitView addSubview:sendBtn];
|
||||
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 5,self.frame.size.width - sendBtn.frame.size.width - 10*2 - 5, 30)];
|
||||
textField.backgroundColor = [UIColor lightGrayColor];
|
||||
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
|
||||
textField.delegate = self;
|
||||
[commitView addSubview:textField];
|
||||
self.inputTextField = textField;
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(keyboardWillHide:)
|
||||
name:UIKeyboardWillHideNotification
|
||||
object:nil];
|
||||
|
||||
}
|
||||
|
||||
-(void)setPalceholderText:(NSString *)palceholderText
|
||||
{
|
||||
_palceholderText = palceholderText;
|
||||
}
|
||||
|
||||
-(void)dismissSelfViewTap{
|
||||
[self removeFromSuperview];
|
||||
}
|
||||
|
||||
-(void)sendBtnAction:(UIButton *)btn{
|
||||
|
||||
[self sendCommend];
|
||||
}
|
||||
|
||||
-(void)sendCommend{
|
||||
|
||||
if (self.inputTextField.text.length > 200) {
|
||||
[[UIApplication sharedApplication].keyWindow makeToast:@"The comments should not exceed 200 words" duration:1 position:CSToastPositionCenter];
|
||||
return;
|
||||
}
|
||||
if (self.inputTextField.text.length == 0) {
|
||||
|
||||
[[UIApplication sharedApplication].keyWindow makeToast:@"Comment content cannot be empty" duration:1 position:CSToastPositionCenter];
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.SendCommentHandler) {
|
||||
self.SendCommentHandler(self.inputTextField.text);
|
||||
}
|
||||
|
||||
[self dismissKeyboard];
|
||||
|
||||
}
|
||||
|
||||
- (void)dismissKeyboard
|
||||
{
|
||||
if ([self.inputTextField becomeFirstResponder]) {
|
||||
[self.inputTextField resignFirstResponder];
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;
|
||||
{
|
||||
if (textField ==self.inputTextField) {
|
||||
textField.placeholder = _palceholderText;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
|
||||
|
||||
if (textField ==self.inputTextField) {
|
||||
[self sendCommend];
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)keyboardWillShow:(NSNotification*)notification {
|
||||
|
||||
// get keyboard size and loctaion
|
||||
CGRect keyboardBounds;
|
||||
[[notification.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue: &keyboardBounds];
|
||||
NSNumber *duration = [notification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
|
||||
NSNumber *curve = [notification.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey];
|
||||
|
||||
// Need to translate the bounds to account for rotation.
|
||||
keyboardBounds = [self convertRect:keyboardBounds toView:nil];
|
||||
|
||||
// get a rect for the textView frame
|
||||
CGRect commentInputViewFrame = self.commitInputView.frame;
|
||||
commentInputViewFrame.origin.y = self.bounds.size.height - (keyboardBounds.size.height + commentInputViewFrame.size.height);
|
||||
|
||||
// animations settings
|
||||
[UIView beginAnimations:nil context:NULL];
|
||||
[UIView setAnimationBeginsFromCurrentState:YES];
|
||||
[UIView setAnimationDuration:[duration doubleValue]];
|
||||
[UIView setAnimationCurve:[curve intValue]];
|
||||
|
||||
// set views with new info
|
||||
self.commitInputView.frame = commentInputViewFrame;
|
||||
|
||||
[UIView commitAnimations];
|
||||
|
||||
|
||||
}
|
||||
|
||||
- (void) keyboardWillHide:(NSNotification *)note
|
||||
{
|
||||
self.commitInputView.frame = CGRectMake(0, self.bounds.size.height - 60, self.bounds.size.width, 60);
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
self.commitInputView = nil;
|
||||
self.inputTextField= nil;
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user