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.
1095 lines
41 KiB
1095 lines
41 KiB
// |
|
// MapViewController.m |
|
// watch |
|
// |
|
// Created by xTT on 2017/7/3. |
|
// Copyright © 2017年 xTT. All rights reserved. |
|
// |
|
|
|
#import "MapViewController.h" |
|
#import "MyMQTT.h" |
|
#import "CustomAnnotationView.h" |
|
#import "CLLocation+YCLocation.h" |
|
#import "UserAnnotationView.h" |
|
#import "MarkViewController.h" |
|
#import "NewTrackVC.h" |
|
#import "RailListViewController.h" |
|
#import "MapReviseViewController.h" |
|
|
|
//高德SDK |
|
#import <AMapFoundationKit/AMapFoundationKit.h> |
|
#import <AMapSearchKit/AMapSearchKit.h> |
|
#import "EllipsePageControl.h" |
|
#import "LineStatusViewController.h" |
|
|
|
//默认的定位位置 北京 |
|
#define DefineLocate CLLocationCoordinate2DMake(39.9086828351,116.3980865479) |
|
|
|
@interface MapViewController ()<CLLocationManagerDelegate,MKMapViewDelegate,AMapSearchDelegate,UIScrollViewDelegate> |
|
|
|
@property (strong, nonatomic) CLLocationManager *locationManager; |
|
@property (strong, nonatomic) Locate *curLocate;// 设备当前的 位置 |
|
@property (strong, nonatomic) CLLocation *userLocate;// 用户当前的 位置 |
|
@property (strong, nonatomic) MKPointAnnotation *curPointAnnotation; //设备 View |
|
@property (strong, nonatomic) MKPointAnnotation *userPointAnnotation; //用户 View |
|
@property (strong, nonatomic) UITapGestureRecognizer *titleViewTap; |
|
@property (strong, nonatomic) UIButton *downBtn; |
|
@property (strong, nonatomic) UILabel *titleLabel; |
|
@property (assign, nonatomic) BOOL isLocating; // 正在定位的标识 |
|
|
|
|
|
@property (nonatomic ,assign) NSInteger scrollIndex; |
|
|
|
///昵称 |
|
@property (nonatomic ,weak) UILabel *nameLabel; |
|
|
|
/// 头像 |
|
@property (nonatomic ,weak) UIImageView *iconImg; |
|
|
|
@property (nonatomic ,strong) UIScrollView *bgScrollView; |
|
|
|
@property (nonatomic ,strong) EllipsePageControl *pageControl; |
|
|
|
/// 电量信息View |
|
@property (nonatomic ,weak) UIView *kwhView; |
|
|
|
//设备电量Image |
|
@property (weak, nonatomic) UIImageView *deviceBatteryImage; |
|
|
|
//设备电量Label |
|
@property (weak, nonatomic) UILabel *deviceBatteryLabel; |
|
|
|
// 定位地址内容标题 |
|
@property (weak, nonatomic) UILabel *locationAddressLabel; |
|
|
|
// 定位类型的显示Image |
|
@property (weak, nonatomic) UIButton *locationTypeImageView; |
|
|
|
// 定位时间 |
|
@property (weak, nonatomic) MyUILabel *locationTimeLabel; |
|
|
|
/// 定位标题数组 |
|
@property (nonatomic ,strong) NSMutableArray *addressLabelArr; |
|
|
|
/// 定位时间数组 |
|
@property (nonatomic ,strong) NSMutableArray *timeLabelArr; |
|
|
|
/// 定位类型的显示Image数组 |
|
@property (nonatomic ,strong) NSMutableArray *typeImageViewArr; |
|
|
|
/// 设备电量数组 |
|
@property (nonatomic ,strong) NSMutableArray *batteryLabelArr; |
|
|
|
/// 设备电量图标数组 |
|
@property (nonatomic ,strong) NSMutableArray *batteryImageArr; |
|
|
|
/// 电量信息View数组 |
|
@property (nonatomic ,strong) NSMutableArray *kwhViewArr; |
|
|
|
/// 昵称数组 |
|
@property (nonatomic ,strong) NSMutableArray *nameLabelArr; |
|
|
|
/// 头像数组 |
|
@property (nonatomic ,strong) NSMutableArray *iconImgArr; |
|
|
|
/** |
|
定位超时的定时器 |
|
*/ |
|
@property (strong, nonatomic) NSTimer *OverTimer; |
|
|
|
/// 不在线提示View |
|
@property (nonatomic ,strong) UIView *onlineStatusView; |
|
|
|
@property (nonatomic, strong) AMapSearchAPI *searchAPI; |
|
|
|
//逆地理编码 |
|
@property (nonatomic, strong) AMapReGeocodeSearchRequest *regeo; |
|
|
|
|
|
@end |
|
|
|
|
|
@implementation MapViewController |
|
-(void)setIsLocating:(BOOL)isLocating{ |
|
_isLocating = isLocating; |
|
if(_isLocating == NO){ |
|
if (self.OverTimer) { |
|
[self.OverTimer invalidate];// 使定时器 失效 |
|
self.OverTimer = nil; |
|
} |
|
} |
|
} |
|
-(void)viewWillAppear:(BOOL)animated{ |
|
[super viewWillAppear:animated]; |
|
[self subMsgView]; |
|
Device *defaultDev = nil; |
|
NSString *defaultImei = [User getDefaultImei]; |
|
if (defaultImei && cUser.myDevices) |
|
{ |
|
for (NSInteger i = 0; i < cUser.myDevices.count; i++) |
|
{ |
|
Device *dev = cUser.myDevices[i]; |
|
if ([defaultImei isEqualToString:dev.imei]) |
|
{ |
|
self.scrollIndex = i; |
|
defaultDev = dev; |
|
[self scrollViewDidScrolls:i]; |
|
break; |
|
} |
|
} |
|
} |
|
[cUser.cDevice getDeviceCurLocationSuccess:^(id responseObject) { |
|
} failure:^(id faiObject) { |
|
}]; |
|
[self loadData]; |
|
|
|
|
|
} |
|
- (void)viewDidLoad { |
|
[super viewDidLoad]; |
|
self.zx_navBarBackgroundColor = KKClearColor; |
|
self.mapView.delegate = self; |
|
// [self setTitleView]; |
|
self.searchAPI = [[AMapSearchAPI alloc] init]; |
|
self.searchAPI.delegate = self; |
|
|
|
[self initLocationManager]; |
|
|
|
self.curPointAnnotation = [[MKPointAnnotation alloc] init]; |
|
self.userPointAnnotation = [[MKPointAnnotation alloc] init]; |
|
WEAKSELF |
|
[[NSNotificationCenter defaultCenter] addObserverForName:PUSH_type_deviceNowLocation |
|
object:nil |
|
queue:[NSOperationQueue mainQueue] |
|
usingBlock:^(NSNotification * _Nonnull note) |
|
{ |
|
//把定位超时的 标识复位 |
|
weakSelf.isLocating = NO; |
|
[SVProgressHUD dismiss]; |
|
//定位的通知 |
|
if ([note.object[@"imei"] isEqualToString:cUser.cDevice.imei]) { |
|
weakSelf.curLocate = [Locate mj_objectWithKeyValues:note.object]; |
|
cUser.cDevice.lastLocation = weakSelf.curLocate; |
|
[weakSelf loadData]; |
|
} |
|
}]; |
|
|
|
|
|
|
|
[self.view addSubview:self.bgScrollView]; |
|
[self.view addSubview:self.onlineStatusView]; |
|
[self.onlineStatusView mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.bottom.equalTo(self.bgScrollView.mas_top).inset(12); |
|
make.left.right.equalTo(self.view).inset(15); |
|
make.height.mas_equalTo(44); |
|
}]; |
|
|
|
// UITapGestureRecognizer *tapPress = [[UITapGestureRecognizer alloc] initWithTarget:self |
|
// action:@selector(mapViewtapPressed:)]; |
|
// [self.mapView addGestureRecognizer:tapPress]; |
|
|
|
|
|
UIView *btnView = [UIView new]; |
|
btnView.frame = CGRectMake(ScreenWidth-48-16, Adapted(94), 48, 208); |
|
btnView.backgroundColor = KKWhiteColorColor; |
|
[self.view addSubview:btnView]; |
|
btnView.conrnerRadius(10).shadowColor(KKTextBlackColor).shadowOffset(CGSizeMake(3, 3)).shadowRadius(5).shadowOpacity(0.1).showVisual(); |
|
|
|
|
|
NSArray *titleArr = @[@"历史轨迹",@"电子围栏",@"定位纠错",@"定位说明"]; |
|
NSArray *imageArr = @[@"icon_baby_history",@"icon_baby_security_fence",@"icon_baby_error",@"icon_baby_description"]; |
|
for (int i = 0; i < titleArr.count; i++) |
|
{ |
|
UIButton *btn = [UIButton new]; |
|
//btn.backgroundColor = mainColor; |
|
btn.frame = CGRectMake(0, i*51, 48, 50); |
|
[btn setTitle:titleArr[i] forState:0]; |
|
[btn setImage:ImageName_(imageArr[i]) forState:0]; |
|
btn.titleLabel.font = Font_(10); |
|
btn.tag = i; |
|
[btn setTitleColor:RGB(20, 20, 20) forState:0]; |
|
[UICommon setTitleAndImage:btn :2]; |
|
[btn addTarget:self action:@selector(btnsTouch:) forControlEvents:UIControlEventTouchUpInside]; |
|
[btnView addSubview:btn]; |
|
|
|
if (i < titleArr.count-1) |
|
{ |
|
UILabel *line = [UILabel new]; |
|
line.backgroundColor = RGB(229, 229, 229); |
|
[btnView addSubview:line]; |
|
[line mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.right.equalTo(btnView).inset(4); |
|
make.top.equalTo(btn.mas_bottom); |
|
make.height.mas_equalTo(1); |
|
}]; |
|
} |
|
} |
|
|
|
/// 刷新按钮 |
|
UIButton *refreshBtn = [UIButton new]; |
|
[refreshBtn setImage:ImageName_(@"icon_baby_read") forState:0]; |
|
refreshBtn.backgroundColor = KKWhiteColorColor; |
|
refreshBtn.tag = 5; |
|
[refreshBtn addTarget:self action:@selector(btnsTouch:) forControlEvents:UIControlEventTouchUpInside]; |
|
[self.view addSubview:refreshBtn]; |
|
[refreshBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.centerX.equalTo(btnView); |
|
make.bottom.equalTo(self.bgScrollView.mas_top).inset(68); |
|
make.size.mas_equalTo(CGSizeMake(48, 48)); |
|
}]; |
|
refreshBtn.conrnerRadius(24).shadowColor(KKTextBlackColor).shadowOffset(CGSizeMake(3, 3)).shadowRadius(5).shadowOpacity(0.1).showVisual(); |
|
|
|
|
|
/// 定位按钮 |
|
UIButton *positioningBtn = [UIButton new]; |
|
[positioningBtn setImage:ImageName_(@"icon_baby_positioning") forState:0]; |
|
positioningBtn.backgroundColor = KKWhiteColorColor; |
|
positioningBtn.tag = 4; |
|
[positioningBtn addTarget:self action:@selector(btnsTouch:) forControlEvents:UIControlEventTouchUpInside]; |
|
[self.view addSubview:positioningBtn]; |
|
[positioningBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.centerX.equalTo(refreshBtn); |
|
make.bottom.equalTo(refreshBtn.mas_top).inset(12); |
|
make.size.mas_equalTo(CGSizeMake(48, 48)); |
|
}]; |
|
positioningBtn.conrnerRadius(24).shadowColor(KKTextBlackColor).shadowOffset(CGSizeMake(3, 3)).shadowRadius(5).shadowOpacity(0.1).showVisual(); |
|
|
|
} |
|
|
|
#pragma mark 按钮点击事件 |
|
/// 按钮点击事件 |
|
- (void)btnsTouch:(UIButton *)sender |
|
{ |
|
switch (sender.tag) |
|
{ |
|
case 0: |
|
{ |
|
///历史轨迹 |
|
// UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]]; |
|
// UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"NewTrackVC"]; |
|
// vc.title = @"历史轨迹"; |
|
// vc.hidesBottomBarWhenPushed = YES; |
|
// [self.navigationController pushViewController:vc animated:YES]; |
|
[UICommon PusXibViewController:[NewTrackVC new] :@"NewTrackVC"]; |
|
} |
|
break; |
|
case 1: |
|
{ |
|
///电子围栏 |
|
// UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]]; |
|
// UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"RailListViewController"]; |
|
// vc.hidesBottomBarWhenPushed = YES; |
|
// [self.navigationController pushViewController:vc animated:YES]; |
|
|
|
[UICommon PusXibViewController:[RailListViewController new] :@"RailListViewController"]; |
|
} |
|
break; |
|
case 2: |
|
{ |
|
///定位纠错 |
|
MapReviseViewController *vc = [[MapReviseViewController alloc] init]; |
|
[self.navigationController pushViewController:vc animated:YES]; |
|
} |
|
break; |
|
case 3: |
|
{ |
|
///定位说明 |
|
MarkViewController *markVC = [[MarkViewController alloc] init]; |
|
[self.navigationController pushViewController:markVC animated:YES]; |
|
} |
|
break; |
|
case 4: |
|
{ |
|
///定位 |
|
//[self getUserLocationAction]; |
|
[self initLocationManager]; |
|
} |
|
break; |
|
case 5: |
|
{ |
|
///刷新定位 |
|
[self getCurLoactionClick]; |
|
} |
|
break; |
|
|
|
default: |
|
break; |
|
} |
|
} |
|
|
|
|
|
- (void)loadData |
|
{ |
|
//[self.locationManager startUpdatingLocation]; |
|
if(cUser.cDevice.lastLocation) |
|
{ |
|
self.curLocate = cUser.cDevice.lastLocation; |
|
[self showCurPiont]; |
|
[self mapView:self.mapView didSelectAnnotationView:[CustomAnnotationView new]]; |
|
// self.deviceBatteryImage.hidden = NO; |
|
// self.deviceBatteryLabel.hidden = NO; |
|
|
|
} |
|
else |
|
{ |
|
[self setMapZoom:DefineLocate]; |
|
// MARK: 做位置未知时的 处理 |
|
self.locationTimeLabel.edgeInsets = UIEdgeInsetsMake(0, 0, 0, 0); |
|
self.locationTimeLabel.text = @""; |
|
self.locationAddressLabel.text = @"当前位置未知,请确保设备开机且能够联网,再点击定位按钮进行定位"; |
|
// self.deviceBatteryImage.hidden = YES; |
|
// self.deviceBatteryLabel.hidden = YES; |
|
[self initLocationManager]; |
|
} |
|
|
|
//MARK: 显示电量 |
|
[self setBattery:cUser.cDevice.battery.intValue]; |
|
|
|
} |
|
|
|
- (void)setBattery:(int)battery |
|
{ |
|
// 电量 |
|
NSString *imageName = @"icon_home_electricity_50"; |
|
self.kwhView.hidden = NO; |
|
if(battery == 0) |
|
{ |
|
imageName = @"icon_home_electricity_0"; |
|
self.kwhView.hidden = YES; |
|
} |
|
else if (battery > 0 && battery < 50) |
|
imageName = @"icon_home_electricity_25"; |
|
else if (battery >= 50 && battery < 75) |
|
imageName = @"icon_home_electricity_50"; |
|
else if (battery >= 75 && battery < 100) |
|
imageName = @"icon_home_electricity_75"; |
|
else if (battery == 100) |
|
imageName = @"icon_home_electricity_100"; |
|
|
|
self.deviceBatteryImage.image = [myHelper getImageWithName:imageName]; |
|
self.deviceBatteryLabel.text = [NSString stringWithFormat:@"%d%%",battery]; |
|
|
|
} |
|
|
|
- (NSMutableArray *)getDeviceNameArr{ |
|
NSMutableArray *nameArr = [NSMutableArray array]; |
|
[cUser.myDevices enumerateObjectsUsingBlock:^(Device * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { |
|
[nameArr addObject:obj.name]; |
|
}]; |
|
return nameArr; |
|
} |
|
|
|
- (void)viewWillDisappear:(BOOL)animated{ |
|
[super viewWillDisappear:animated]; |
|
[self.locationManager stopUpdatingHeading]; |
|
} |
|
|
|
|
|
/** |
|
//MARK:获取当前设备的定位信息 |
|
*/ |
|
- (void)getCurLoactionClick |
|
{ |
|
if(self.isLocating){ |
|
return; |
|
} |
|
//先移动 到 设备的定位处 |
|
// if([cUser.cDevice.lastLocation.lon doubleValue] == 0 |
|
// && [cUser.cDevice.lastLocation.lat doubleValue] == 0){ |
|
// [self setMapZoom:DefineLocate]; |
|
// } |
|
// else |
|
if([cUser.cDevice.lastLocation.lon doubleValue] != 0 |
|
&& [cUser.cDevice.lastLocation.lat doubleValue] != 0) |
|
{ |
|
[self setMapZoom:CLLocationCoordinate2DMake([cUser.cDevice.lastLocation.lat doubleValue], [cUser.cDevice.lastLocation.lon doubleValue])]; |
|
} |
|
|
|
WEAKSELF |
|
[cUser.cDevice getDeviceCurLocationSuccess:^(id responseObject) { |
|
//请求成功 等待位置回传 显示 loading |
|
[SVProgressHUD showWithStatus:@"定位中,请稍后..."]; |
|
|
|
weakSelf.isLocating = YES; |
|
weakSelf.OverTimer = [NSTimer scheduledTimerWithTimeInterval:15 repeats:NO block:^(NSTimer * _Nonnull timer) { |
|
if(weakSelf.isLocating){ |
|
weakSelf.isLocating = NO; |
|
[SVProgressHUD dismiss]; |
|
} |
|
|
|
}]; |
|
|
|
} failure:^(id faiObject) { |
|
if([faiObject isKindOfClass:[NSDictionary class]]){ |
|
//5001 |
|
if([faiObject[@"code"] intValue] == HTTP_ERROR_5001){ |
|
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:nil message:@"定位失败,当前设备可能关机、欠费、或处于弱信号环境" style:LGAlertViewStyleAlert buttonTitles:@[@"确定"] cancelButtonTitle:nil destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { |
|
|
|
} cancelHandler:nil destructiveHandler:nil]; |
|
//获取当前的 VC |
|
UIViewController *vc = weakSelf.navigationController.viewControllers.lastObject; |
|
if([vc isKindOfClass:[MapViewController class]]){ |
|
[alertView showAnimated:YES completionHandler:nil]; |
|
} |
|
} |
|
|
|
} |
|
}]; |
|
} |
|
|
|
/** |
|
获取当前用户的定位信息 |
|
*/ |
|
- (void)getUserLocationAction |
|
{ |
|
[self.mapView setCenterCoordinate:self.userLocate.coordinate animated:YES]; |
|
//调整位置 |
|
//设置用户点 为当前地图范围的中心点 |
|
CLLocationCoordinate2D center = self.userLocate.coordinate; |
|
if(center.latitude == 0 && center.longitude == 0){ |
|
center = DefineLocate; |
|
} |
|
[self setMapZoom:center]; |
|
|
|
[self mapView:self.mapView didSelectAnnotationView:[UserAnnotationView new]]; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
//缩小地图 |
|
- (IBAction)subtractBtnAction:(id)sender { |
|
//设置地图范围 |
|
//设置中心点为当前地图范围的中心点 |
|
CLLocationCoordinate2D center = self.mapView.region.center; |
|
//设置跨度为当前地图范围的跨度 * 比例系数 |
|
MKCoordinateSpan span = MKCoordinateSpanMake(self.mapView.region.span.latitudeDelta * 2, self.mapView.region.span.longitudeDelta * 2); |
|
|
|
//设置范围 |
|
@try { |
|
MKCoordinateRegion region = MKCoordinateRegionMake(center, span); |
|
xLog(@"span %@",[NSValue valueWithMKCoordinateSpan:span]) |
|
xLog(@"center %@",[NSValue valueWithMKCoordinate:center]) |
|
|
|
[self.mapView setRegion: region animated:YES]; |
|
|
|
} @catch (NSException *exception) { |
|
xLog(@"error: %@",exception.description); |
|
} @finally { |
|
|
|
} |
|
|
|
|
|
} |
|
|
|
/** |
|
//MARK:点击地图触发的方法 |
|
*/ |
|
- (void)mapViewtapPressed:(id)sender{ |
|
[SVProgressHUD dismiss]; |
|
} |
|
|
|
#pragma 定位 |
|
- (void)initLocationManager |
|
{ |
|
// self.locationManager = [[CLLocationManager alloc] init]; |
|
// self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; |
|
// self.locationManager.delegate = self; |
|
// |
|
// if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { |
|
// [self.locationManager requestWhenInUseAuthorization]; |
|
// } |
|
|
|
[_mapView setShowsUserLocation:YES]; |
|
} |
|
|
|
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation |
|
{ |
|
CLLocationCoordinate2D coord = [userLocation coordinate]; |
|
NSLog(@"当前位置(经度:%f,纬度:%f)",coord.longitude,coord.latitude); |
|
if (coord.longitude) |
|
{ |
|
[_mapView setShowsUserLocation:NO]; |
|
CLLocation *ccl = [[CLLocation alloc] initWithLatitude:coord.latitude longitude:coord.longitude]; |
|
self.userLocate = ccl; |
|
[User currentUser].curLocation = ccl; |
|
[self showCurPiont]; |
|
} |
|
} |
|
|
|
//- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status { |
|
// switch (status) { |
|
// case kCLAuthorizationStatusNotDetermined: |
|
// if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { |
|
// [self.locationManager requestWhenInUseAuthorization]; |
|
// } |
|
// break; |
|
// default: |
|
// break; |
|
// } |
|
//} |
|
////MARK : 初始化 用户位置 |
|
//-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations |
|
//{ |
|
// CLLocation *userLocation = [locations lastObject]; |
|
// self.userLocate = userLocation; |
|
// [User currentUser].curLocation = userLocation; |
|
// [manager stopUpdatingLocation]; |
|
// |
|
// // [self showCurPiont]; |
|
// //直接 调一次 |
|
// |
|
// Device *device = cUser.myDevices[self.scrollIndex]; |
|
// if(!self.curLocate && !device.onlineStatus.boolValue) |
|
//// { |
|
//// [self mapView:self.mapView didSelectAnnotationView:[CustomAnnotationView new]]; |
|
//// } |
|
//// else |
|
// { |
|
// [self mapView:self.mapView didSelectAnnotationView:[UserAnnotationView new]]; |
|
// [self showCurPiont]; |
|
// } |
|
// |
|
//} |
|
|
|
|
|
|
|
//MARK: 显示点 |
|
/** |
|
显示点 |
|
*/ |
|
-(void)showCurPiont |
|
{ |
|
//要在地图上显示的点的数组 |
|
NSMutableArray *pointArr = [NSMutableArray array]; |
|
|
|
CLLocationCoordinate2D coordinate2D = DefineLocate; |
|
if (cUser.cDevice.lastLocation) |
|
{ |
|
//设置新的地图信息 |
|
coordinate2D = CLLocationCoordinate2DMake([self.curLocate.lat doubleValue], |
|
[self.curLocate.lon doubleValue]); |
|
//删除原来的设备点 |
|
if ([self.mapView.annotations containsObject:self.curPointAnnotation]) |
|
[self.mapView removeAnnotation:self.curPointAnnotation]; |
|
|
|
//删除原来的用户点 |
|
if ([self.mapView.annotations containsObject:self.userPointAnnotation]) |
|
[self.mapView removeAnnotation:self.userPointAnnotation]; |
|
|
|
self.curPointAnnotation.coordinate = coordinate2D; |
|
|
|
// 设备的 范围框 |
|
if (self.curLocate.radius) |
|
{ |
|
CLLocationDistance radius = [self.curLocate.radius doubleValue]; |
|
MKCircle *circle = [MKCircle circleWithCenterCoordinate:coordinate2D |
|
radius:radius]; |
|
[self.mapView removeOverlays:self.mapView.overlays]; |
|
[self.mapView addOverlay:circle]; |
|
} |
|
[pointArr addObject:self.curPointAnnotation]; |
|
|
|
if(pointArr.count > 0) |
|
{ |
|
//如果 设备的位置存在则显示 设备的位置 |
|
[self.mapView addAnnotations:pointArr]; |
|
[self setMapZoom:coordinate2D]; |
|
|
|
} |
|
} |
|
else |
|
{ |
|
//设置新的地图信息 |
|
coordinate2D = CLLocationCoordinate2DMake(self.userLocate.coordinate.latitude, |
|
self.userLocate.coordinate.longitude); |
|
//删除原来的设备点 |
|
if ([self.mapView.annotations containsObject:self.curPointAnnotation]) |
|
[self.mapView removeAnnotation:self.curPointAnnotation]; |
|
|
|
//删除原来的用户点 |
|
if ([self.mapView.annotations containsObject:self.userPointAnnotation]) |
|
[self.mapView removeAnnotation:self.userPointAnnotation]; |
|
self.userPointAnnotation.coordinate = coordinate2D; |
|
[self.mapView removeOverlays:self.mapView.overlays]; |
|
// 设备的 范围框 |
|
// if (self.curLocate.radius) { |
|
// CLLocationDistance radius = [self.curLocate.radius doubleValue]; |
|
// MKCircle *circle = [MKCircle circleWithCenterCoordinate:coordinate2D |
|
// radius:radius]; |
|
// [self.mapView removeOverlays:self.mapView.overlays]; |
|
// [self.mapView addOverlay:circle]; |
|
// } |
|
[pointArr addObject:self.userPointAnnotation]; |
|
|
|
if(pointArr.count > 0) |
|
{ |
|
[self.mapView addAnnotations:pointArr]; |
|
[self setMapZoom:coordinate2D]; |
|
|
|
} |
|
|
|
// //调整位置 |
|
// //设置中心点为当前地图范围的中心点 |
|
// CLLocationCoordinate2D center = DefineLocate; |
|
// //不存在 则 显示用户的位置 |
|
// if(self.mapView.userLocation.isUpdating){ |
|
// center = self.mapView.userLocation.coordinate; |
|
// }else if(self.userLocate){ |
|
// center = self.userLocate.coordinate; |
|
// } |
|
// [self setMapZoom:center]; |
|
} |
|
} |
|
|
|
#pragma 缩小地图 |
|
- (void)setMapZoom:(CLLocationCoordinate2D)centerCoordinate |
|
{ |
|
// if (self.mapView.region.span.latitudeDelta > 20) { |
|
|
|
// MARK: carh update by lsz 22-5-12 增加坐标合法性判断 |
|
@try { |
|
if (CLLocationCoordinate2DIsValid(centerCoordinate)) { |
|
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(centerCoordinate, 2000, 2000); |
|
[self.mapView setRegion:region animated:YES]; |
|
} |
|
} @catch (NSException *exception) { |
|
|
|
} @finally { |
|
|
|
} |
|
|
|
//} |
|
} |
|
|
|
#pragma mark - 地图控件代理方法 |
|
#pragma mark 显示大头针时调用,注意方法中的annotation参数是即将显示的大头针对象 |
|
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation |
|
{ |
|
if([annotation isEqual:self.curPointAnnotation]) |
|
{ |
|
//由于当前位置的标注也是一个大头针,所以此时需要判断,此代理方法返回nil使用默认大头针视图 |
|
static NSString *key1=@"CustomAnnotationView"; |
|
CustomAnnotationView *annotationView = (CustomAnnotationView*)[_mapView dequeueReusableAnnotationViewWithIdentifier:key1]; |
|
//如果缓存池中不存在则新建 |
|
if (!annotationView) { |
|
annotationView =[[CustomAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:key1]; |
|
annotationView.canShowCallout=NO;//不允许交互点击 |
|
|
|
}else{ |
|
//重新设置此类大头针视图的大头针模型(因为有可能是从缓存池中取出来的,位置是放到缓存池时的位置) |
|
annotationView.annotation = annotation; |
|
} |
|
//修改大头针视图 设置成头像 |
|
[annotationView setImageWithURLString:cUser.cDevice.avator]; |
|
|
|
annotationView.frame = CGRectMake(0, 0, 40.5, 60); |
|
//设置中心偏移量 |
|
annotationView.centerOffset = CGPointMake(0, -26); |
|
//定义详情视图偏移量 |
|
annotationView.calloutOffset=CGPointMake(0, 12); |
|
return annotationView; |
|
} |
|
// else if([annotation isKindOfClass:[MKUserLocation class]]) |
|
else if([annotation isEqual:self.userPointAnnotation]) |
|
{ |
|
//由于当前位置的标注也是一个大头针,所以此时需要判断,此代理方法返回nil使用默认大头针视图 |
|
static NSString *key1=@"UserAnnotationView"; |
|
UserAnnotationView *annotationView = (UserAnnotationView*)[_mapView dequeueReusableAnnotationViewWithIdentifier:key1]; |
|
//如果缓存池中不存在则新建 |
|
if (!annotationView) { |
|
annotationView =[[UserAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:key1]; |
|
annotationView.canShowCallout=NO;//不允许交互点击 |
|
|
|
}else{ |
|
//重新设置此类大头针视图的大头针模型(因为有可能是从缓存池中取出来的,位置是放到缓存池时的位置) |
|
annotationView.annotation = annotation; |
|
} |
|
//修改大头针视图 设置成头像 |
|
[annotationView setImageWithURLString:cUser.avator]; |
|
//设置大小 |
|
annotationView.frame = CGRectMake(0, 0, 40.5, 60); |
|
//设置中心偏移量 |
|
annotationView.centerOffset = CGPointMake(0, -26); |
|
//定义详情视图偏移量 |
|
annotationView.calloutOffset=CGPointMake(0, 12); |
|
return annotationView; |
|
} |
|
return nil; |
|
} |
|
|
|
//MARK: 点击地图 中的 标点 触发的方法 |
|
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view |
|
{ |
|
if([view isKindOfClass:[CustomAnnotationView class]]) |
|
{ |
|
// 设备点 |
|
if ([self.curLocate.loc_type isEqualToString:@"LBS"]) { |
|
[self.locationTypeImageView setImage:ImageName_(@"icon_home_base_station") forState:0]; |
|
}else if([self.curLocate.loc_type isEqualToString:@"GPS"]){ |
|
[self.locationTypeImageView setImage:ImageName_(@"icon_home_base_gps") forState:0]; |
|
}else if([self.curLocate.loc_type isEqualToString:@"WIFI"]){ |
|
[self.locationTypeImageView setImage:ImageName_(@"icon_home_base_wifi") forState:0]; |
|
}else{ |
|
//是空的 LBS |
|
[self.locationTypeImageView setImage:ImageName_(@"icon_home_base_station") forState:0]; |
|
} |
|
if(self.curLocate){ |
|
NSString *dateStr = [myHelper distanceTimeWithBeforeTime:[self.curLocate.timestamp doubleValue]]; |
|
self.locationTimeLabel.edgeInsets = UIEdgeInsetsMake(0, 6, 0, 6); |
|
self.locationTimeLabel.text = dateStr; |
|
self.locationAddressLabel.text = @"位置解析中..."; |
|
} |
|
|
|
self.regeo.location = [AMapGeoPoint locationWithLatitude:[self.curLocate.lat floatValue] longitude:[self.curLocate.lon floatValue]]; |
|
[self.searchAPI AMapReGoecodeSearch:self.regeo]; |
|
|
|
} |
|
// else |
|
// { |
|
// AMapReGeocodeSearchRequest *regeo = [[AMapReGeocodeSearchRequest alloc] init]; |
|
// regeo.location = [AMapGeoPoint locationWithLatitude:self.userLocate.coordinate.latitude longitude:self.userLocate.coordinate.longitude]; |
|
// [self.searchAPI AMapReGoecodeSearch:regeo]; |
|
// |
|
// } |
|
} |
|
|
|
- (AMapReGeocodeSearchRequest *)regeo { |
|
if (!_regeo) { |
|
_regeo = [[AMapReGeocodeSearchRequest alloc]init]; |
|
_regeo.requireExtension = YES; |
|
} |
|
return _regeo; |
|
} |
|
|
|
|
|
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay |
|
{ |
|
if ([overlay isKindOfClass:[MKCircle class]]) |
|
{ |
|
MKCircleRenderer *circle = [[MKCircleRenderer alloc] initWithOverlay:overlay]; |
|
circle.strokeColor = [UIColor clearColor]; |
|
|
|
circle.fillColor = [[UIColor blueColor] colorWithAlphaComponent:0.1]; |
|
|
|
// circle.lineWidth = 1; |
|
return circle; |
|
} |
|
|
|
return nil; |
|
} |
|
|
|
#pragma mark ====高德地图位置解析回调==== |
|
-(void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMapReGeocodeSearchResponse *)response{ |
|
if (response.regeocode != nil) |
|
{ |
|
NSString *name = response.regeocode.formattedAddress; |
|
self.locationAddressLabel.text = name; |
|
} |
|
} |
|
|
|
|
|
-(void)dealloc{ |
|
if(self.OverTimer){ |
|
[self.OverTimer invalidate]; |
|
self.OverTimer = nil; |
|
} |
|
} |
|
|
|
- (void)didReceiveMemoryWarning { |
|
[super didReceiveMemoryWarning]; |
|
// Dispose of any resources that can be recreated. |
|
switch (self.mapView.mapType) { |
|
case MKMapTypeHybrid: |
|
{ |
|
self.mapView.mapType = MKMapTypeStandard; |
|
} |
|
break; |
|
case MKMapTypeStandard: |
|
{ |
|
self.mapView.mapType = MKMapTypeHybrid; |
|
} |
|
break; |
|
default: |
|
break; |
|
} |
|
self.mapView.mapType = MKMapTypeStandard; |
|
} |
|
|
|
|
|
- (UIScrollView *)bgScrollView |
|
{ |
|
if (!_bgScrollView) |
|
{ |
|
_bgScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(10, ScreenHeight-Adapted(88)-TabBarHeight-32, ScreenWidth-20, 88)]; |
|
_bgScrollView.delegate = self; |
|
_bgScrollView.clipsToBounds = NO; |
|
_bgScrollView.backgroundColor = KKClearColor; |
|
// 是否按照页(默认以scrollview的宽度或高度为一页) |
|
_bgScrollView.pagingEnabled = YES; |
|
// 是否显示右侧边界显示的竖向指示条 |
|
_bgScrollView.showsVerticalScrollIndicator = NO; |
|
// 是否显示底侧边界显示的横向指示条 |
|
_bgScrollView.showsHorizontalScrollIndicator = NO; |
|
// 是否显示侧边界显示的指示条的颜色样式 |
|
_bgScrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite; |
|
|
|
[self.view addSubview:self.pageControl]; |
|
} |
|
return _bgScrollView; |
|
} |
|
|
|
- (void)subMsgView |
|
{ |
|
NSArray *watchArr = cUser.myDevices; |
|
CGFloat hh = watchArr.count > 1 ? 32 : 16; |
|
self.pageControl.numberOfPages = watchArr.count; |
|
CGFloat ww = watchArr.count*6+watchArr.count*8; // 计算分页控件长度 |
|
self.bgScrollView.contentSize = CGSizeMake(self.bgScrollView.width *watchArr.count, 88); |
|
self.pageControl.frame = CGRectMake((ScreenWidth-ww)/2, _bgScrollView.bottom+5, ww, 10); |
|
self.pageControl.hidden = watchArr.count > 1 ? NO : YES; |
|
self.bgScrollView.frame = CGRectMake(10, ScreenHeight-Adapted(88)-TabBarHeight-hh, ScreenWidth-20, 88); |
|
|
|
for (UIView *views in self.bgScrollView.subviews) |
|
{ |
|
[views removeFromSuperview]; |
|
} |
|
self.addressLabelArr = [[NSMutableArray alloc] init]; |
|
self.timeLabelArr = [[NSMutableArray alloc] init]; |
|
self.typeImageViewArr = [[NSMutableArray alloc] init]; |
|
self.batteryLabelArr = [[NSMutableArray alloc] init]; |
|
self.nameLabelArr = [[NSMutableArray alloc] init]; |
|
self.iconImgArr = [[NSMutableArray alloc] init]; |
|
self.kwhViewArr = [[NSMutableArray alloc] init]; |
|
for (int i = 0; i < watchArr.count; i++) |
|
{ |
|
Device *dev = watchArr[i]; |
|
CGRect fromt = CGRectMake(self.bgScrollView.width*i+5, 0,self.bgScrollView.width-10 , 88); |
|
UIView *bgView = [UICommon ui_view:fromt backgroundColor:KKWhiteColorColor cornerRadius:12 borderWidth:0 borderColor:KKWhiteColorColor]; |
|
[self.bgScrollView addSubview:bgView]; |
|
bgView.conrnerRadius(12).shadowColor(KKTextBlackColor).shadowOffset(CGSizeMake(3, 3)).shadowRadius(5).shadowOpacity(0.1).showVisual(); |
|
|
|
UIImageView *iconImg = [UICommon ui_imageView:CGRectZero fileName:[dev.sex isEqualToString:@"girl"] ? @"icon_girl_head_portrait" : @"icon_boy_head_portrait"]; |
|
if (dev.avator && ![dev.avator containsString:@"/default.jpg"]) |
|
[iconImg sd_setImageWithURL:[NSURL URLWithString:dev.avator] placeholderImage:ImageName_(@"")]; |
|
iconImg.layer.cornerRadius = 8; |
|
iconImg.layer.masksToBounds = YES; |
|
// self.iconImg = iconImg; |
|
[bgView addSubview:iconImg]; |
|
[iconImg mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.centerY.equalTo(bgView); |
|
make.left.equalTo(bgView).offset(16); |
|
make.size.mas_equalTo(CGSizeMake(56, 56)); |
|
}]; |
|
|
|
/// 右箭头 |
|
UIImageView *rightImg = [UICommon ui_imageView:CGRectZero fileName:@"icon_enter_gray"]; |
|
[bgView addSubview:rightImg]; |
|
[rightImg mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.centerY.equalTo(iconImg); |
|
make.right.equalTo(bgView.mas_right).inset(15); |
|
make.size.mas_equalTo(rightImg.image.size); |
|
}]; |
|
|
|
|
|
/// 昵称 |
|
UILabel *nameLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontBold_(20) textColor:KKTextBlackColor text:dev.name Radius:0]; |
|
//self.nameLabel = nameLabel; |
|
[bgView addSubview:nameLabel]; |
|
[nameLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.equalTo(iconImg.mas_right).offset(8); |
|
make.top.equalTo(iconImg).offset(4); |
|
}]; |
|
|
|
// 定位时间 |
|
MyUILabel *locationTimeLabel = [UICommon ui_myLabel:CGRectZero lines:0 align:NSTextAlignmentCenter font:Font_(10) textColor:KKGrey102 text:@"" Radius:10]; |
|
locationTimeLabel.backgroundColor = RGB(246, 246, 246); |
|
//self.locationTimeLabel = locationTimeLabel; |
|
[bgView addSubview:locationTimeLabel]; |
|
[locationTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.equalTo(nameLabel.mas_right).offset(5); |
|
make.centerY.equalTo(nameLabel); |
|
make.height.mas_equalTo(20); |
|
}]; |
|
|
|
UIButton *locationTypeImageView = [UIButton new]; |
|
locationTypeImageView.backgroundColor = RGB(246, 246, 246); |
|
[locationTypeImageView setImage:ImageName_(@"icon_home_base_station") forState:0]; |
|
locationTypeImageView.layer.cornerRadius = 10; |
|
locationTypeImageView.layer.masksToBounds = YES; |
|
//self.locationTypeImageView = locationTypeImageView; |
|
[bgView addSubview:locationTypeImageView]; |
|
[locationTypeImageView mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.equalTo(locationTimeLabel.mas_right).offset(5); |
|
make.centerY.equalTo(nameLabel); |
|
make.height.width.mas_equalTo(20); |
|
}]; |
|
|
|
/// 电量信息View |
|
UIView *kwhView = [[UIView alloc] init]; |
|
kwhView.backgroundColor = RGBA(16, 199, 114, .18); |
|
kwhView.layer.cornerRadius = 10; |
|
kwhView.layer.masksToBounds = YES; |
|
//self.kwhView = kwhView; |
|
[bgView addSubview:kwhView]; |
|
[kwhView mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.equalTo(locationTypeImageView.mas_right).offset(5); |
|
make.centerY.equalTo(nameLabel); |
|
make.size.mas_equalTo(CGSizeMake(50, 20)); |
|
}]; |
|
|
|
NSString *imageName = @"icon_home_electricity_50"; |
|
if(dev.battery.intValue == 0) |
|
imageName = @"icon_home_electricity_0"; |
|
else if (dev.battery.intValue > 0 && dev.battery.intValue < 50) |
|
imageName = @"icon_home_electricity_25"; |
|
else if (dev.battery.intValue >= 50 && dev.battery.intValue < 75) |
|
imageName = @"icon_home_electricity_50"; |
|
else if (dev.battery.intValue >= 75 && dev.battery.intValue < 100) |
|
imageName = @"icon_home_electricity_75"; |
|
else if (dev.battery.intValue == 100) |
|
imageName = @"icon_home_electricity_100"; |
|
|
|
/// 电量 |
|
UIImageView *deviceBatteryImage = [UICommon ui_imageView:CGRectZero fileName:imageName]; |
|
//self.deviceBatteryImage = deviceBatteryImage; |
|
[kwhView addSubview:deviceBatteryImage]; |
|
[deviceBatteryImage mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.centerY.equalTo(kwhView); |
|
make.left.equalTo(kwhView).offset(6); |
|
make.size.mas_equalTo(CGSizeMake(Adapted(12), Adapted(12))); |
|
}]; |
|
|
|
/// 电量 |
|
UILabel *deviceBatteryLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:Font_(9) textColor:RGB(16, 199, 114) text:[NSString stringWithFormat:@"%@%%",dev.battery] Radius:0]; |
|
//self.deviceBatteryLabel = deviceBatteryLabel; |
|
[kwhView addSubview:deviceBatteryLabel]; |
|
[deviceBatteryLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.centerY.equalTo(kwhView); |
|
make.left.equalTo(deviceBatteryImage.mas_right).offset(4); |
|
}]; |
|
|
|
UILabel *locationAddressLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentLeft font:Font_(12) textColor:KKGrey102 text:@"" Radius:0]; |
|
//self.locationAddressLabel = locationAddressLabel; |
|
[bgView addSubview:locationAddressLabel]; |
|
[locationAddressLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.equalTo(nameLabel); |
|
make.top.equalTo(nameLabel.mas_bottom).offset(4); |
|
make.right.equalTo(rightImg.mas_left).inset(10); |
|
}]; |
|
[self.addressLabelArr addObject:locationAddressLabel]; |
|
[self.timeLabelArr addObject:locationTimeLabel]; |
|
[self.batteryLabelArr addObject:deviceBatteryLabel]; |
|
[self.typeImageViewArr addObject:locationTypeImageView]; |
|
[self.batteryImageArr addObject:deviceBatteryImage]; |
|
[self.nameLabelArr addObject:nameLabel]; |
|
[self.iconImgArr addObject:iconImg]; |
|
[self.kwhViewArr addObject:kwhView]; |
|
} |
|
} |
|
|
|
//UIScrollView内视图移动停止移动时调用 |
|
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView |
|
{ |
|
CGFloat pageWidth = self.bgScrollView.width; |
|
NSInteger currentPage = floor((self.bgScrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1; |
|
NSLog(@"滚动到了第 %ld 页",currentPage); |
|
self.pageControl.currentPage = currentPage; |
|
self.scrollIndex = currentPage; |
|
Device *device = cUser.myDevices[currentPage]; |
|
[User saveDefaultImei:device.imei]; |
|
cUser.cDevice = device; |
|
[self switchView]; |
|
[self loadData]; |
|
} |
|
|
|
/// 滚动到指定页 |
|
- (void)scrollViewDidScrolls:(NSInteger)index |
|
{ |
|
CGFloat imageW = self.bgScrollView.width; |
|
// 指定页面 |
|
CGPoint position = CGPointMake(index*imageW, 0); |
|
[self.bgScrollView setContentOffset:position animated:NO]; |
|
self.pageControl.currentPage = index; |
|
[self switchView]; |
|
} |
|
|
|
/// 实时切换手表显示View |
|
- (void)switchView |
|
{ |
|
self.locationAddressLabel = (UILabel *)self.addressLabelArr[self.scrollIndex]; |
|
self.locationTimeLabel = (MyUILabel *)self.timeLabelArr[self.scrollIndex]; |
|
self.deviceBatteryLabel = (UILabel *)self.batteryLabelArr[self.scrollIndex]; |
|
self.locationTypeImageView = (UIButton *)self.typeImageViewArr[self.scrollIndex]; |
|
self.deviceBatteryImage = (UIImageView *)self.batteryImageArr[self.scrollIndex]; |
|
self.nameLabel = (UILabel *)self.nameLabelArr[self.scrollIndex]; |
|
self.iconImg = (UIImageView *)self.iconImgArr[self.scrollIndex]; |
|
self.kwhView = (UIView *)self.kwhViewArr[self.scrollIndex]; |
|
|
|
Device *device = cUser.myDevices[self.scrollIndex]; |
|
self.onlineStatusView.hidden = device.onlineStatus.boolValue; |
|
} |
|
|
|
-(EllipsePageControl *)pageControl |
|
{ |
|
if (!_pageControl) |
|
{ |
|
_pageControl = [[EllipsePageControl alloc] init]; |
|
_pageControl.backgroundColor = KKClearColor; |
|
_pageControl.otherColor = KKGrey153; |
|
_pageControl.currentColor = mainColor; |
|
} |
|
return _pageControl; |
|
} |
|
|
|
- (UIView *)onlineStatusView |
|
{ |
|
if (!_onlineStatusView) |
|
{ |
|
_onlineStatusView = [UICommon ui_view:CGRectZero backgroundColor:RGB(255, 235, 238) cornerRadius:10 borderWidth:0 borderColor:KKWhiteColorColor]; |
|
_onlineStatusView.hidden = YES; |
|
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGuestures:)]; |
|
[_onlineStatusView addGestureRecognizer:tapGesture]; |
|
|
|
UIImageView *leftImg = [UICommon ui_imageView:CGRectZero fileName:@"comm_ti_icon"]; |
|
[_onlineStatusView addSubview:leftImg]; |
|
[leftImg mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.equalTo(_onlineStatusView).offset(15); |
|
make.centerY.equalTo(_onlineStatusView); |
|
make.size.mas_equalTo(leftImg.image.size); |
|
}]; |
|
|
|
/// 右箭头 |
|
UIImageView *rightImg = [UICommon ui_imageView:CGRectZero fileName:@"comm_right_icon_red"]; |
|
[_onlineStatusView addSubview:rightImg]; |
|
[rightImg mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.centerY.equalTo(_onlineStatusView); |
|
make.right.equalTo(_onlineStatusView.mas_right).inset(15); |
|
make.size.mas_equalTo(rightImg.image.size); |
|
}]; |
|
|
|
UILabel *titleLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentLeft font:FontBold_(14) textColor:RGB(255, 84, 71) text:@"手表未连网络,可能关机,欠费或信号差" Radius:0]; |
|
[_onlineStatusView addSubview:titleLabel]; |
|
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.right.equalTo(rightImg.mas_left).inset(5); |
|
make.centerY.equalTo(_onlineStatusView.mas_centerY); |
|
make.left.equalTo(leftImg.mas_right).offset(5); |
|
}]; |
|
|
|
|
|
} |
|
return _onlineStatusView; |
|
} |
|
|
|
- (void)handleGuestures:(UITapGestureRecognizer *)sender |
|
{ |
|
CGPoint point = [sender locationInView:self.onlineStatusView]; |
|
if([self.onlineStatusView.layer containsPoint:point]) |
|
{ |
|
LineStatusViewController *vc = [[LineStatusViewController alloc] init]; |
|
[self.navigationController pushViewController:vc animated:YES]; |
|
} |
|
} |
|
|
|
@end
|
|
|