This commit is contained in:
lianxiang
2018-09-06 21:19:50 +08:00
parent 17d4481f2c
commit 0f09748cc8
69 changed files with 966 additions and 439 deletions
+113 -45
View File
@@ -13,71 +13,131 @@
#import "GiGaCommentModel.h"
#import "LXDanMuManagerConfig.h"
#import "IQKeyboardManager.h"
#import <SocketIO/SocketIO-Swift.h>
#import "NSString+Unicode.h"
//弹幕控制器
@interface GiGaFlingCommitVC ()
@property (nonatomic,strong) GiGaFlyingCommitInputView *commitInputView;
@property (nonatomic,strong) SocketIOClient *client;
@property (nonatomic,strong) SocketManager *manager;
@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];
NC_ADD_TARGET_NAME_OBJECT(self, @selector(maskTimeEnd), kUserNoti_MASKEND, nil);
[IQKeyboardManager sharedManager].enable = NO;
[[IQKeyboardManager sharedManager] setEnableAutoToolbar:NO];
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
NC_REMOVE_NAME(self, kUserNoti_MASKEND, nil);
[IQKeyboardManager sharedManager].enable = YES;
[[IQKeyboardManager sharedManager] setEnableAutoToolbar: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;
- (void)viewDidLoad {
GiGaCommentModel *model = [[GiGaCommentModel alloc]init];
model.userName = nameArray[nameRandomIndex];
model.msg = msgArray[msgRandomIndex];
model.userAvatar = avatarArray[avatarRandomIndex];
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.view addSubview: self.commitInputView];
weakify(self);
self.commitInputView.SendCommentHandler = ^(NSString *content) {
GILog(@"发送->:%@",content);
NSArray *arr = @[@{
@"content":content,
@"room":@"",
@"sendUserName":@"lianxiang"
}];
[weakSelf.client emit:@"talk" with:arr];
};
//开启弹幕
[[LXDanMuManager shareInstance] createDanmuWithTrackSpeedArray:@[@1.00,@1.00,@3.00,@4.00] centerY:KMainH / 4 trackWidth:KMainW showInView:self.view];
[[LXDanMuManager shareInstance] start];
//socket
[self connetction];
}
-(void)connetction{
NSURL* url = [[NSURL alloc] initWithString:@"http://wsyts.s1.natapp.cc"];
// NSDictionary* headers = @{@"EncodeUTF8":@YES};
SocketManager *manager = [[SocketManager alloc] initWithSocketURL:url config:@{@"log": @NO, @"forcePolling": @YES,@"connectParams":@{@"token":@""},@"doubleEncodeUTF8":@YES}];
_manager = manager;
_client = manager.defaultSocket;
[self.manager connect];
weakify(self);
[self.client on:@"connect" callback:^(NSArray* data, SocketAckEmitter* ack) {
NSLog(@"*************\n\niOS客户端上线\n\n*************");
}];
[self.client on:@"connectedSocket" callback:^(NSArray * _Nonnull event, SocketAckEmitter * _Nonnull ack) {
NSLog(@"connectedSocket:%@",event);
}];
[self.client on:@"onTalk" callback:^(NSArray * _Nonnull envent, SocketAckEmitter * _Nonnull ack) {
NSString *json =envent[0];
NSLog(@"callback json***:%@",json);
NSDictionary *dic = [GiGaHelper dictionaryWithJsonString:json];
if (dic == nil) {
NSLog(@"解析失败");
}else{
GiGaCommentModel *commentModel = [[GiGaCommentModel alloc] initWithDictionary:dic error:nil];
GILog(@"接收->:%@",[dic[@"content"] replaceUnicode:dic[@"content"]]);
[weakSelf showDanMuWith:commentModel];
}
}];
[self.client on:@"disconnect" callback:^(NSArray * _Nonnull event, SocketAckEmitter * _Nonnull ack) {
NSLog(@"*************\n\niOS客户端下线\n\n*************%@",event?event[0]:@"");
}];
[self.client on:@"error" callback:^(NSArray * _Nonnull event, SocketAckEmitter * _Nonnull ack) {
// NSString *htmlString =event[0];
// htmlString = [self htmlEntityDecode:htmlString];
//
// UIWebView * webView = [[UIWebView alloc]initWithFrame:CGRectMake(20, 300, self.view.frame.size.width - 40, 400)];
// [webView loadHTMLString:htmlString baseURL:nil];
// [self.view addSubview:webView];
//
// NSLog(@"*************\n\n%@\n\n*************",event?event[0]:@"");
GILog(@"请求超时");
}];
}
- (GiGaFlyingCommitInputView *)commitInputView{
if (!_commitInputView) {
_commitInputView = [[GiGaFlyingCommitInputView alloc] initWithFrame:self.view.bounds];
[_commitInputView setPalceholderText:@"请输入弹幕"];
}
return _commitInputView;
}
//弹幕插入
-(void)showDanMuWith:(GiGaCommentModel *)model{
NSArray *classArray = @[@"GiGaCommentView",@"GiGaCommentView"];
int classRandomIndex = arc4random() % 2;
GiGaCommentView *customView = [[NSClassFromString(classArray[classRandomIndex]) alloc] initWithMsgModel:model height:TRACK_HEIGHT];
[[LXDanMuManager shareInstance] appendDanMuWithCustomView:customView toTrackIndex:-1];
}
@@ -90,11 +150,19 @@
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)dealloc{
NC_REMOVE_NAME(self, kUserNoti_MASKEND, nil);
NSLog(@"dealloc");
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[self.manager disconnectSocket:self.client];
[self.manager disconnect];
[self.client disconnect];
self.client = nil;
self.manager = nil;
[self dismissViewControllerAnimated:YES completion:nil];
}
@end
@@ -34,64 +34,45 @@
}
@property(nonatomic,strong)MaskViewBootomWaringView *waringView;
@property(nonatomic,strong)UILabel *descLabl;
@property(nonatomic,strong)UIView *descBackView;
//@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,strong) MaskTimeCircularProgressView *cicleProgressView;
@property(nonatomic,strong) UIImageView *swipeGaurdimagView;
@property(nonatomic,strong) UIButton *startMaskButton;
@property(nonatomic,strong) UIButton *startTestButton;
@end
@implementation GiGaMaskTaskViewController
//提示label
- (UILabel *)descLabl{
if(!_descLabl){
_descLabl = [[UILabel alloc] init];
_descLabl.text = @"请点击或按住面膜上滑敷到脸部开始倒计时";
_descLabl.textAlignment = NSTextAlignmentCenter;
_descLabl.numberOfLines = 2;
_descLabl.textColor = GIGARGB(89, 216, 197, 1);
_descLabl.font = [UIFont fontWithName:GIGA_FONTNAME size:11];
}
return _descLabl;
}
- (UIView *)descBackView{
if(!_descBackView){
_descBackView = [[UIView alloc] init];
_descBackView.layer.borderWidth = 1;
_descBackView.layer.borderColor = GIGARGB(120, 217, 202, 1).CGColor;
_descBackView.layer.masksToBounds = YES;
_descBackView.layer.cornerRadius = 1;
}
return _descBackView;
}
#pragma mark - property
//面膜
- (UIImageView *)maskImageView{
if (!_maskImageView) {
_maskImageView = [[UIImageView alloc] init];
_maskImageView.userInteractionEnabled = YES;
//_maskImageView.backgroundColor = [UIColor purpleColor];
_maskImageView.image = [UIImage imageNamed:@"img_bg"];
UIPanGestureRecognizer *pangesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureAction:)];
[_maskImageView addGestureRecognizer:pangesture];
_maskImageView.image = [UIImage imageNamed:@"img_mask"];
UISwipeGestureRecognizer * upSwipeGesture = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(maskupSwipeGesture)];
[upSwipeGesture setDirection:(UISwipeGestureRecognizerDirectionUp)];
[_maskImageView addGestureRecognizer:upSwipeGesture];
UITapGestureRecognizer *tapgesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(maskTapAction)];
[_maskImageView addGestureRecognizer:tapgesture];
}
return _maskImageView;
}
//人脸
- (UIImageView *)faceView{
if (!_faceView) {
_faceView = [[UIImageView alloc] init];
//_faceView.backgroundColor = [UIColor lightGrayColor];
_faceView.userInteractionEnabled = YES;
_faceView.image = [UIImage imageNamed:@"img_bg_head"];
_faceView.image = [UIImage imageNamed:@"bg_img_face"];
}
return _faceView;
}
@@ -107,6 +88,40 @@
}
return _cicleProgressView;
}
//⬆️
- (UIImageView *)swipeGaurdimagView{
if (!_swipeGaurdimagView) {
_swipeGaurdimagView = [[UIImageView alloc] init];
_swipeGaurdimagView.image = [UIImage imageNamed:@"mask_bg_up"];
}
return _swipeGaurdimagView;
}
//开始面膜
- (UIButton *)startMaskButton{
if (!_startMaskButton) {
_startMaskButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_startMaskButton setBackgroundImage:[UIImage imageNamed:@"btn_start_mask"] forState:UIControlStateNormal];
NSAttributedString *title = [GiGaHelper stringWithText:@"开始敷面膜" textColor:[UIColor whiteColor] textFont:GIGA_TEXTFONTMEDIUM(13) leterSpace:0];
[_startMaskButton setAttributedTitle:title forState:UIControlStateNormal];
[_startMaskButton addTarget:self action:@selector(startMaskButtonAction) forControlEvents:UIControlEventTouchUpInside];
}
return _startMaskButton;
}
//开始测试
- (UIButton *)startTestButton{
if (!_startTestButton) {
_startTestButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_startTestButton setBackgroundImage:[UIImage imageNamed:@"btn_start_test"] forState:UIControlStateNormal];
NSAttributedString *title = [GiGaHelper stringWithText:@"测试肤质" textColor:[UIColor whiteColor] textFont:GIGA_TEXTFONTBOLD(18) leterSpace:0];
[_startTestButton setAttributedTitle:title forState:UIControlStateNormal];
[_startTestButton addTarget:self action:@selector(testBtnAcion:) forControlEvents:UIControlEventTouchUpInside];
}
return _startTestButton;
}
//底部提示栏
- (MaskViewBootomWaringView *)waringView{
@@ -127,80 +142,14 @@
}else{
GiGaFlingVC.modalPresentationStyle = UIModalPresentationCurrentContext;
}
GiGaFlingVC.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
GiGaFlingVC.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
[self presentViewController:GiGaFlingVC animated:NO completion:nil];
}
//滑动手势
-(void)panGestureAction:(UIPanGestureRecognizer *)pan{
CGPoint panLocation = [pan locationInView:self.view];
NSLog(@"panlocation.y:%f",panLocation.y);
if (pan.state == UIGestureRecognizerStateBegan) {
[self animaMask];
}else if (pan.state == UIGestureRecognizerStateChanged){
}else if (pan.state == UIGestureRecognizerStateEnded){
}else{
}
}
#pragma mark -开始面膜时间动画
-(void)animaMask{
self.descLabl.hidden = YES;
self.descBackView.hidden = YES;
[self.view layoutIfNeeded];
[UIView animateWithDuration:1.0 animations:^{
[self.maskImageView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.attachPoint.y - 118);
}];
[self.faceView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.attachPoint.y -174);
}];
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
self.cicleProgressView.hidden = NO;
self.maskImageView.userInteractionEnabled = NO;
//开始面膜时间
[self startMaskTime];
}];
}
#pragma mark 面膜时间结束复原动画
-(void)endMaskAnimation{
self.cicleProgressView.hidden = YES;
self.descLabl.hidden = NO;
self.descBackView.hidden = NO;
[self.view layoutIfNeeded];
[UIView animateWithDuration:1.0 animations:^{
[self.maskImageView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(314 + PhoneX_TopMargin);
}];
[self.faceView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(103 + PhoneX_TopMargin);
}];
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
self.maskImageView.userInteractionEnabled = YES;
}];
}
#pragma mark - 生命周期
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
}
-(void)viewDidAppear:(BOOL)animated{
@@ -233,49 +182,121 @@
}
#pragma mark - 响应事件
#pragma mark 上滑动手势
-(void)maskupSwipeGesture{
[self animaMask];
}
#pragma mark 点击手势
-(void)maskTapAction{
[self animaMask];
}
#pragma mark 点击测试按钮
-(void)startMaskButtonAction{
[self animaMask];
}
#pragma mark - 开始面膜时间动画
-(void)animaMask{
self.swipeGaurdimagView.hidden = YES;
self.startMaskButton.hidden = YES;
self.startTestButton.hidden = YES;
[self.view layoutIfNeeded];
[UIView animateWithDuration:1.0 animations:^{
[self.maskImageView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.attachPoint.y - 87);
}];
[self.faceView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.attachPoint.y -124);
}];
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
self.cicleProgressView.hidden = NO;
self.maskImageView.userInteractionEnabled = NO;
//开始面膜时间
[self startMaskTime];
}];
}
#pragma mark 面膜时间结束复原动画
-(void)endMaskAnimation{
self.cicleProgressView.hidden = YES;
self.swipeGaurdimagView.hidden = NO;
self.startMaskButton.hidden = NO;
self.startTestButton.hidden = NO;
[self.view layoutIfNeeded];
[UIView animateWithDuration:1.0 animations:^{
[self.maskImageView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(254 + PhoneX_TopMargin);
}];
[self.faceView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(91 + PhoneX_TopMargin);
}];
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
self.maskImageView.userInteractionEnabled = YES;
}];
}
#pragma mark 布局
-(void)initUI{
self.view.backgroundColor = GIGARGB(56, 56, 56, 1);
self.view.backgroundColor = GIGA_MAIN_BGCOLOR;
[self.view addSubview:self.maskImageView];
[self.view addSubview:self.faceView];
[self.view bringSubviewToFront:self.maskImageView];
[self.view addSubview:self.descBackView];
[self.view addSubview:self.swipeGaurdimagView];
[self.view addSubview:self.startMaskButton];
[self.view addSubview:self.startTestButton];
[self.view addSubview:self.cicleProgressView];
//face
[self.faceView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.view.mas_top).offset(103 + PhoneX_TopMargin);
make.left.mas_equalTo(self.view.mas_centerX).offset(-69);
make.size.mas_equalTo(CGSizeMake(138, 174));
make.top.mas_equalTo(self.view.mas_top).offset(91 + PhoneX_TopMargin);
make.size.mas_equalTo(CGSizeMake(99, 124));
make.centerX.mas_equalTo(self.view.mas_centerX);
}];
//mask
[self.maskImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.view.mas_top).offset(314 + PhoneX_TopMargin);
make.left.mas_equalTo(self.view.mas_centerX).offset(-51);
make.size.mas_equalTo(CGSizeMake(102, 118));
}];
//描述
[self.descBackView mas_makeConstraints:^(MASConstraintMaker *make){
make.top.mas_equalTo(500 + PhoneX_TopMargin);
make.width.mas_equalTo(149);
make.height.mas_equalTo(45);
make.top.mas_equalTo(self.view.mas_top).offset(254 + PhoneX_TopMargin);
make.size.mas_equalTo(CGSizeMake(72, 87));
make.centerX.mas_equalTo(self.view.mas_centerX);
}];
[self.descBackView addSubview:self.descLabl];
//up
[self.swipeGaurdimagView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.view.mas_top).offset(368);
make.width.and.height.mas_equalTo(20);
make.centerX.mas_equalTo(self.view.mas_centerX);
[self.descLabl mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(121);
make.height.mas_equalTo(32);
make.center.mas_equalTo(self.descBackView.center);
}];
//startMask
[self.startMaskButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.view.mas_top).offset(412);
make.size.mas_equalTo(CGSizeMake(117, 25));
make.centerX.mas_equalTo(self.view.mas_centerX);
}];
//startTest
[self.startTestButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.view.mas_top).offset(486);
make.size.mas_equalTo(CGSizeMake(132, 41));
make.centerX.mas_equalTo(self.view.mas_centerX);
}];
}];
// UIButton *testBtn = [UIButton buttonWithType:UIButtonTypeCustom];
@@ -403,6 +424,8 @@
#pragma mark 开始测试
-(void)testBtnAcion:(UIButton *)btn{
[self createInputView];
return;
BOOL isUserLogin = [GiGaUserDefault isUserLogin];
@@ -478,17 +501,18 @@
#pragma mark - setUpNav
-(void)setUpNav{
//leftItem
UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
leftBtn.frame = CGRectMake(0, 0, 40, 40);
leftBtn.backgroundColor = [UIColor redColor];
[leftBtn setImage:[UIImage imageNamed:@"btn_back"] forState:UIControlStateNormal];
[leftBtn addTarget:self action:@selector(leftBtnAction) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
// UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
// leftBtn.frame = CGRectMake(0, 0, 40, 40);
// leftBtn.backgroundColor = [UIColor redColor];
// [leftBtn setImage:[UIImage imageNamed:@"btn_back"] forState:UIControlStateNormal];
// [leftBtn addTarget:self action:@selector(leftBtnAction) forControlEvents:UIControlEventTouchUpInside];
// self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
//rightItem
UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
rightBtn.frame = CGRectMake(0, 0, 40, 40);
rightBtn.backgroundColor = [UIColor blueColor];
[rightBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
//rightBtn.backgroundColor = [UIColor blueColor];
[rightBtn setImage:[UIImage imageNamed:@"nav_circle_avatar"] forState:UIControlStateNormal];
[rightBtn addTarget:self action:@selector(rightBtnAction) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
@@ -18,7 +18,6 @@
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
//self.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
[self creatUI];