You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.4 KiB

//
// DeviceSwitchover.m
// tongxin
//
// Created by ecell on 2023/7/7.
// Copyright © 2023 xTT. All rights reserved.
//
#import "DeviceSwitchover.h"
#import "User.h"
#import "Device.h"
@interface DeviceSwitchover ()<YBPopupMenuDelegate>
/// 是否有添加
@property (nonatomic ,assign) BOOL isAdd;
@end
@implementation DeviceSwitchover
+ (instancetype)sharedManager
{
static dispatch_once_t onceToken;
static DeviceSwitchover *apitance;
dispatch_once(&onceToken, ^{
apitance = [[DeviceSwitchover alloc] init];
});
return apitance;
}
- (void)showMenuViewWithAdd:(BOOL)add Point:(CGPoint)point
{
self.isAdd = add;
//CGPoint p = CGPointMake(ScreenWidth - 30, getRectNavAndStatusHight - 10);
NSMutableArray *titles = [NSMutableArray new];
NSMutableArray *icons = [NSMutableArray new];
// 显示切换列表
if(cUser.myDevices.count != 0)
{
for (Device *device in cUser.myDevices)
{
if (device.avator && ![device.avator containsString:@"/default.jpg"])
{
[icons addObject:device.avator];
}
else
{
//根据男女区分
NSString *icon = @"";
if([device.sex isEqualToString:@"girl"])
icon = @"icon_girl_head_portrait";
else
icon = @"icon_boy_head_portrait";
[icons addObject:[UIImage imageNamed:icon]];
}
[titles addObject:device.name];
}
}
//添加 --- 添加设备
if(add)
{
[titles insertObject:@"添加设备" atIndex:0];
[icons insertObject:ImageName_(@"icon_add_watch") atIndex:0];
}
[YBPopupMenu showAtPoint:point titles:titles icons:nil menuWidth:120*(ScreenWidth/320) otherSettings:^(YBPopupMenu *popupMenu) {
popupMenu.textColor = KKTextColor;
popupMenu.fontSize = 15;
popupMenu.cornerRadius = 4.0f;
popupMenu.dismissOnSelected = YES;
popupMenu.delegate = self;
popupMenu.offset = 5;
popupMenu.type = YBPopupMenuTypeDefault;
}];
}
#pragma mark - YBPopupMenuDelegate 代理方法
- (void)ybPopupMenuDidSelectedAtIndex:(NSInteger)index ybPopupMenu:(YBPopupMenu *)ybPopupMenu {
[ybPopupMenu dismiss];
self.switchDevice(index);
//Device *device = cUser.myDevices[index];
//[self switchDeviceWithDevice:device];
}
@end