123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- //
- // FriendsListViewController.m
- // Unity-iPhone
- //
- // Created by duowan123 on 2022/9/2.
- //
- #import "FriendsListViewController.h"
- #import "FriendsListView.h"
- @interface FriendsListViewController ()<FriendsListViewDelegate>
- //
- @property (strong, nonatomic)FriendsListView * friendsListCarouselView;
- //button
- @property(nonatomic,strong)UIButton * nextButton;//
- @property(nonatomic,strong)UIButton * lastButton;//
- @property(nonatomic,strong)UIButton * cancelButton;//
- @property(nonatomic,strong)UIButton * connectButton;//
- @property (nonatomic,strong)UIButton * clearnButton;//清理缓存
- //留白
- @property(nonatomic,strong)NoDeviceTip * tipView;
- @end
- @implementation FriendsListViewController
- -(void)viewDidLoad{
-
- [super viewDidLoad];
- [self initUI];
-
- }
- #pragma mark -- create UI
- -(void)initUI{
-
- //创建需要的毛玻璃特效类型
- UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
- //创建毛玻璃视图
- UIVisualEffectView *visualV = [[UIVisualEffectView alloc] initWithEffect:blur];
- visualV.frame = self.view.bounds;
- //可以通过透明度来达到模糊程序的改变.
- visualV.effect = nil;
- visualV.backgroundColor = [UIColor blackColor];
- visualV.alpha = 0.5;
- [UIView animateWithDuration:1 animations:^{
- visualV.effect = blur;
- }];
- [self.view addSubview:visualV];
-
- //无设备
- [self.view addSubview:self.tipView];
-
- //列表
- self.friendsListCarouselView = [[FriendsListView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-SCALEoefficient(200), SCREEN_HEIGHT-SCALEoefficient(100))];
- self.friendsListCarouselView.centerX = self.view.centerX;
- self.friendsListCarouselView.centerY = self.view.centerY-20;
- [self.view addSubview:self.friendsListCarouselView];
- self.friendsListCarouselView.delegate = self;
-
- //上一个
- self.nextButton = [UIButton buttonWithType:UIButtonTypeSystem];
- self.nextButton.frame = CGRectMake(0, 0, SCALEoefficient(16), SCALEoefficient(32));
- self.nextButton.centerY = self.friendsListCarouselView.centerY;
- self.nextButton.right = self.friendsListCarouselView.left+10;
- [self.nextButton setBackgroundImage:[MYFactoryManager imageString:@"gamepop_leftarrow"] forState:UIControlStateNormal];
- [self.view addSubview:self.nextButton];
- [self.nextButton addTarget:self action:@selector(lastAction) forControlEvents:UIControlEventTouchUpInside];
- self.nextButton.backgroundColor = [UIColor clearColor];
- //下一个
- self.lastButton = [UIButton buttonWithType:UIButtonTypeSystem];
- self.lastButton.frame = CGRectMake(0, 0, SCALEoefficient(16), SCALEoefficient(32));
- self.lastButton.centerY = self.friendsListCarouselView.centerY;
- self.lastButton.left = self.friendsListCarouselView.right-10;
- [self.lastButton setBackgroundImage:[MYFactoryManager imageString:@"gamepop_rihtarrow"] forState:UIControlStateNormal];
- [self.view addSubview:self.lastButton];
- [self.lastButton addTarget:self action:@selector(nextAction) forControlEvents:UIControlEventTouchUpInside];
- self.lastButton.backgroundColor = [UIColor clearColor];
-
- //关闭弹窗
- self.cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
- self.cancelButton.frame = CGRectMake(SCREEN_WIDTH-SCALEoefficient(100+20),SCALEoefficient(15), SCALEoefficient(100), SCALEoefficient(30));
- [self.cancelButton setTitle:@"左踮脚 · 返回" forState:UIControlStateNormal];
- [self.cancelButton setImage:[MYFactoryManager imageString:@"gamepop_close_notes"] forState:UIControlStateNormal];
- [self.cancelButton setFont: [UIFont boldSystemFontOfSize: SCALEoefficient(12)]];
- [self.cancelButton.titleLabel setTextColor:[UIColor whiteColor]];
- self.cancelButton.backgroundColor = [UIColor clearColor];
- [self.cancelButton setImageEdgeInsets:UIEdgeInsetsMake(0, SCALEoefficient(-10), 0, 0)];
- [self.cancelButton addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:self.cancelButton];
-
- //隐藏的清理缓存的按钮
- self.clearnButton = [UIButton buttonWithType:UIButtonTypeCustom];
- self.clearnButton.frame = CGRectMake(0, SCREEN_HEIGHT-SCALEoefficient(30)-SCALEoefficient(25), SCALEoefficient(60), SCALEoefficient(25));
- self.clearnButton.backgroundColor = [UIColor clearColor];
- [self.clearnButton addTarget:self action:@selector(clearCacheWithFilePath) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:self.clearnButton];
- NSArray * array = @[@"gamepop_leftarrow_notes",@"gamepop_rihgtarrow_notes",@"gamepop_determine_notes"];
- NSArray * titleArray = @[@"左踏 · 上一个",@"右踏 · 下一个",@"右踮脚 · 确认"];
- for (int i =0; i<3; i++){
- UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
- // button.frame = CGRectMake(SCREEN_WIDTH-SCALEoefficient(62+20+20)*(4-i),SCALEoefficient(23), SCALEoefficient(62+20), SCALEoefficient(20));
- button.frame = CGRectMake(SCREEN_WIDTH/3*i,SCREEN_HEIGHT-SCALEoefficient(30), SCREEN_WIDTH/3, SCALEoefficient(30));
- [button setTitle:titleArray[i] forState:UIControlStateNormal];
- [button setImage:[MYFactoryManager imageString:array[i]] forState:UIControlStateNormal];
- [button setFont: [UIFont boldSystemFontOfSize: SCALEoefficient(10)]];
- [button.titleLabel setTextColor:[UIColor whiteColor]];
- // button.tag = i;
- button.backgroundColor = [UIColor blackColor];
- [button setImageEdgeInsets:UIEdgeInsetsMake(0, SCALEoefficient(-10), 0, 0)];
- // [searchButton addTarget:self action:@selector(mapBtnClick:) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:button];
- }
-
- }
- #pragma mark -------------- 外部事件
- //刷新蓝牙数据
- -(void)reloadData{
-
- if (self.friendsArray.count==0){
- self.tipView.hidden = NO;
- }else{
-
- self.tipView.hidden = YES;
-
- NSMutableArray * dataArr = [NSMutableArray new];
- for (int i = 0; i<self.friendsArray.count; i++){
- UserFriendsModel *model = [[UserFriendsModel alloc]init];
- NSDictionary * dict = self.friendsArray[i];
- NSDictionary * user = dict[@"user"];
- model.status = dict[@"status"];
- model.numberId = i;
- [model setValuesForKeysWithDictionary:user];
- [dataArr addObject:model];
- }
- [self.friendsListCarouselView setArrayData:dataArr];
- }
-
- }
- //蓝牙传过来的脚步交互动作
- -(void)getInteraction:(int)interaction{
-
- if (interaction == 0){//原地 -- 复位
-
- }else if(interaction == 3){//左踩 -- 选中上一个设备
-
- [self lastAction];
- }else if(interaction == 4){//右踩 -- 选中下一个设备
-
- [self nextAction];
- }else if(interaction == 6){//左垫脚 -- 关闭弹窗
-
- [self closeAction];
-
- }else if(interaction == 5){//右垫脚 -- 链接设备
-
- if (self.inviteFriendBlock){
- self.inviteFriendBlock(self.userFriendsModel);
- }
- [self closeAction];
-
- }
-
- }
- ////点击搜索按钮(暂留)
- //-(void)searchAction{
- //
- // self.tipView.hidden = NO;
- // if(self.searchDeviceTask){
- // [BTDataInstance initCBCentralManager];
- // }
- //
- //}
- #pragma mark -------------- 点击界面交互Action
- //选中上一个设备
- - (void)lastAction{
- [self.friendsListCarouselView yw_gotoNext:-1];
- }
- //选中下一个设备
- -(void)nextAction{
- [self.friendsListCarouselView yw_gotoNext:1];
- }
- //关闭弹窗
- - (void)closeAction{
-
- if (self.closeBlock){
- self.closeBlock();
- }
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [UIView animateWithDuration:0.25 animations:^{
- self.view.alpha = 0;
- [self.view removeFromSuperview];
- }completion:^(BOOL finished){
- [self.view removeFromSuperview];
- }];
- });
-
- }
- //清理缓存
- -(void)clearCacheWithFilePath{
- [DebugViewInstance clearCacheWithFilePath];
- }
- #pragma mark -------------- shoesCarouseView delegate
- -(void)setCurrentFriend:(UserFriendsModel*)model{
- self.userFriendsModel = model;
- }
- -(void)connectFriend:(UserFriendsModel*)model{
-
- self.userFriendsModel = model;
- //链接蓝牙
- if (self.inviteFriendBlock){
- self.inviteFriendBlock(self.userFriendsModel);
- }
- [self closeAction];
-
- }
- #pragma mark -------------- lazy
- -(NSMutableArray*)friendsArray{
- if (!_friendsArray){
- _friendsArray = [NSMutableArray new];
- }
- return _friendsArray;
-
- }
- -(NoDeviceTip*)tipView{
-
- if (!_tipView){
- _tipView = [[NoDeviceTip alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2-50, SCREEN_HEIGHT/2-100, 100, 150)];
- _tipView.centerY = self.friendsListCarouselView.centerY;
- _tipView.hidden = NO;
- }
- return _tipView;
-
- }
- @end
|