美文网首页
iOS ~ 高德地图:1、示例:

iOS ~ 高德地图:1、示例:

作者: 阳光下的叶子呵 | 来源:发表于2022-08-31 10:27 被阅读0次

【iOS~ 高德地图:2、示例:台风运行轨迹 + 自定义气泡标注:】
【iOS~ 高德地图:3、自定义气泡标注】
图片覆盖物:【气温】、【降水】
点平滑移动:【台风】
点标注+气泡标注:【自定义气泡标注】
图片覆盖物,使用NSTimer,时间轴(时间刻度)循环更改图片覆盖物,原理:删除,置为nil,在重新创建

if (self.groundOverlay != nil) {
      [self.mapView removeOverlay:self.groundOverlay]; // 点击台风的时候,删掉覆盖物层,在需要的时候重新创建
      self.groundOverlay = nil;
}
######正式代码:ViewController.m:

/** 高德地图 */

import <AMapFoundationKit/AMapFoundationKit.h> // 高德地图 需要引入AMapFoundationKit.h头文件

import <MAMapKit/MAMapKit.h> // 3D矢量图

import <AMapLocationKit/AMapLocationKit.h> // 实现持续定位

/// tabBar雷达 信息:气温+降水(图片)

import "GWHomeRaderMap_DataModel.h"

/// 点击地图之后,显示该坐标的天气信息(自定义气泡标注)

import "GWHomeRaderMap_LocationWeatherModel.h"

import "GWRaderMap_CustomAnnotationView.h"// 自定义气泡view

@interface GWHomeRaderMapCTRL () <MAMapViewDelegate, AMapLocationManagerDelegate>

@property (nonatomic, strong) UIButton *tempBut; // 气温
@property (nonatomic, strong) UIButton *aqiBut; // 空气(暂时 无)
@property (nonatomic, strong) UIButton *rainBut; // 降水
@property (nonatomic, strong) UIButton *typhoonBut;// 台风

/** 1、高德地图 */
@property (nonatomic, strong) UIView *mapBackView;
@property (nonatomic, strong) MAMapView *mapView;
// 定位
@property (nonatomic, strong) AMapLocationManager *locationManager;

// 【图片覆盖物】
@property (nonatomic, strong) MAGroundOverlay *groundOverlay;
@property (nonatomic, assign) MACoordinateBounds coordinateBounds; // 东北、西南两个点定义的四边形经纬度范围

/** 2、自定义:功能 */
/// 气候等级
@property (nonatomic, strong) UIView *climateRank_BackView;
@property (nonatomic, strong) UIImageView *climateRank_Img;
@property (nonatomic, strong) UILabel *climateRank_minTipsL;
@property (nonatomic, strong) UILabel *climateRank_maxTipsL;
/// 当前位置
@property (nonatomic, strong) UIButton *currentPositionBut;

/** 3、播放/暂停:气候变化,(可以 手动滑动 刻度) */
@property (nonatomic, strong) UIView *progress_BackView; // 宽度:290
@property (nonatomic, strong) UIButton *progress_playBut;
@property (nonatomic, strong) UILabel *progress_beginTimeL;
@property (nonatomic, strong) UILabel *progress_endTimeL;
@property (nonatomic, strong) UIView *progress_lineBackView; // 刻度的父view,宽度:(290 - 40 -25) = 225
@property (nonatomic, strong) UIView *progress_currentLineView; // 当前刻度view
@property (nonatomic, strong) UILabel *progress_tipsL; // 日期 时间:“08-10 12:00”

@property (nonatomic, strong) UIView *progress_view; // 覆盖在最上边的一个view(// Touch触摸 view视图)

/** 4、台风:经度、纬度、风力、最大风速、中心气压、距离本地 */
@property (nonatomic, strong) UIView *typhoon_BackView;
@property (nonatomic, strong) UILabel *noTyphoon_tipsL;

@property (nonatomic, strong) UILabel *typhoon_longitudeTipsL;
@property (nonatomic, strong) UILabel *typhoon_longitudeL;
@property (nonatomic, strong) UILabel *typhoon_latitudeTipsL;
@property (nonatomic, strong) UILabel *typhoon_latitudeL;
@property (nonatomic, strong) UILabel *typhoon_windTipsL;
@property (nonatomic, strong) UILabel *typhoon_windL;
@property (nonatomic, strong) UILabel *typhoon_maxWindSpeedTipsL;
@property (nonatomic, strong) UILabel *typhoon_maxWindSpeedL;
@property (nonatomic, strong) UILabel *typhoon_pressureTipsL;
@property (nonatomic, strong) UILabel *typhoon_pressureL;
@property (nonatomic, strong) UILabel *typhoon_distanceTipsL;
@property (nonatomic, strong) UILabel *typhoon_distanceL;

// 【绘制折线 覆盖物】
@property (nonatomic, strong) MAPolyline *commonPolyline;
@property (nonatomic, strong) MAAnimatedAnnotation *typhoon_AnimatedAnnotation; // 台风动画

//@property (nonatomic, strong) MAAnnotationView *typhoon_AnnotationView; // 台风标注view
//@property (nonatomic, strong) MAPointAnnotation *typhoon_PointAnnotation;
@property (nonatomic, strong) MAAnimatedAnnotation *locatinWeather_AnimatedAnnotation; // 点击地图,弹出自定义天气view

/** 雷达数据 */
@property (nonatomic, strong) GWHomeRaderMap_DataModel *raderMapDateModel;
@property (nonatomic, strong) GWHomeRaderMap_LocationWeatherModel *locationWeatherModel;

@property (nonatomic, strong) NSArray *tempImageArray; // 气温图片数组
@property (nonatomic, strong) NSArray *rainImageArray; // 降水图片数组

@property (nonatomic, strong) NSArray *currentImageArray; // 当前的图片数组

@property (nonatomic, assign) NSInteger itemCell; // 第几个图片的索引值
@property (nonatomic, strong) NSTimer *timer;

@end

@implementation GWHomeRaderMapCTRL

  • (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = RGBA(248, 246, 242, 1);
    // self.navigationBar.hidden = YES;
    self.statusBg.hidden = YES;
    self.leftButton.hidden = YES;
    self.rightButton.hidden = YES;
    self.navigationBar.backgroundColor = [UIColor clearColor];

// 用户授权高德SDK隐私协议状态(必须在AMapLocationManager实例化之前调用)
[AMapLocationManager updatePrivacyAgree:AMapPrivacyAgreeStatusDidAgree];
[AMapLocationManager updatePrivacyShow:AMapPrivacyShowStatusDidShow privacyInfo:AMapPrivacyInfoStatusDidContain];

[self setupUI];
[self setMapUI];
[self settingMapLocation];
[self setupTempAndRainOtherFunction];
[self setupTyphoonOtherFunction];
[self gainTempAndRainImages_Request]; // 请求接口时,地图滑不动,(后期解决一下)

}

  • (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
if (_timer) {
    [_timer invalidate];
    _timer = nil;
}
self.tempBut.selected = YES;
self.rainBut.selected = NO;
self.typhoonBut.selected = NO;
self.aqiBut.selected = NO;
self.climateRank_BackView.hidden = NO;
self.climateRank_Img.image = [UIImage imageNamed:@"raderMap_TempRankColor_icon"];
self.climateRank_minTipsL.text = @"-40°";
self.climateRank_maxTipsL.text = @"40°";
self.progress_playBut.selected = NO;
self.typhoon_BackView.hidden = YES;
if (self.tempImageArray.count > 0) {
    [self showTemp_Action];
}
if (self.raderMapDateModel == nil) {
    [self gainTempAndRainImages_Request];
}


// 判断 📌定位 是否开启(自定义方法)
[[LCM_Tool shareInstance] gainCurrentLoaction_latitudeAndLongitude];


//(高德)调用AMapLocationManager提供的startUpdatingLocation方法开启持续定位。(调用此方法会cancel掉所有的单次定位请求。)

// [self startSerialLocation];

//(高德)单次定位:
[self.locationManager requestLocationWithReGeocode:YES completionBlock:^(CLLocation *location, AMapLocationReGeocode *regeocode, NSError *error) {
    if (error == nil) {
        NSLog(@"😆😆 单次定位");
        
    }
    
    NSLog(@"location:{纬度lat:%f; 经度lon:%f; 精确度accuracy:%f}", location.coordinate.latitude, location.coordinate.longitude, location.horizontalAccuracy);
    if (regeocode)
      {
          NSLog(@"reGeocode:%@", regeocode);
      }

// self.mapView.centerCoordinate = location.coordinate;
// [self.mapView setCenterCoordinate:location.coordinate animated:YES];
// [self.mapView setCenterCoordinate:self.mapView.userLocation.location.coordinate animated:YES];

    /**
     regeocode = AMapLocationReGeocode:{formattedAddress:北京市朝阳区东三环购物中心; country:中国;province:北京市; city:北京市; district:朝阳区; citycode:010; adcode:110105; street:东三环; number:***大厦1层; POIName:***大厦购物中心; AOIName:***大厦购物中心;}
     */
    
}];

}

  • (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    }

  • (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];

    //(高德)取消持续定位 (和 单次定位)
    [self stopSerialLocation];
    }

pragma mark -- ---- 点击 navigation 换不同的气候图像 ---- --

  • (void)clickRaderMapBotton:(UIButton *)titleBut {

    if (self.currentImageArray.count <= 0 || (self.itemCell >= self.currentImageArray.count && self.currentImageArray.count > 0)) {
    return;
    }

    self.climateRank_BackView.hidden = NO;
    self.currentPositionBut.hidden = NO;
    self.progress_BackView.hidden = NO;
    self.progress_tipsL.hidden = NO;

    self.progress_currentLineView.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/375(40-1), 0, [UIScreen mainScreen].bounds.size.width/3752, [UIScreen mainScreen].bounds.size.width/375*22);

    self.typhoon_BackView.hidden = YES;

    if (titleBut == self.tempBut) {
    self.tempBut.selected = YES;
    self.rainBut.selected = NO;
    self.typhoonBut.selected = NO;
    self.aqiBut.selected = NO;
    self.climateRank_Img.image = [UIImage imageNamed:@"raderMap_TempRankColor_icon"];
    self.climateRank_minTipsL.text = @"-40°";
    self.climateRank_maxTipsL.text = @"40°";

      [self showTemp_Action];
      [self gain_ClickMap_Request_WithLocationCoordinate:self.mapView.userLocation.location.coordinate];
    

    } else if (titleBut == self.rainBut) {
    self.tempBut.selected = NO;
    self.rainBut.selected = YES;
    self.typhoonBut.selected = NO;
    self.aqiBut.selected = NO;
    self.climateRank_Img.image = [UIImage imageNamed:@"raderMap_RainRankColor_icon"];
    self.climateRank_minTipsL.text = @"小";
    self.climateRank_maxTipsL.text = @"大";

      [self showRain_Action];
      [self gain_ClickMap_Request_WithLocationCoordinate:self.mapView.userLocation.location.coordinate];
    

    } else if (titleBut == self.typhoonBut) {
    self.tempBut.selected = NO;
    self.rainBut.selected = NO;
    self.typhoonBut.selected = YES;
    self.aqiBut.selected = NO;
    self.climateRank_BackView.hidden = YES;
    self.currentPositionBut.hidden = YES;
    self.progress_BackView.hidden = YES;
    self.progress_tipsL.hidden = YES;
    self.typhoon_BackView.hidden = NO;

      if (self.raderMapDateModel.typhoon.count <= 0) { // 无台风
          self.typhoon_longitudeTipsL.hidden = YES;
          self.typhoon_longitudeL.hidden = YES;
          self.typhoon_latitudeTipsL.hidden = YES;
          self.typhoon_latitudeL.hidden = YES;
          self.typhoon_maxWindSpeedTipsL.hidden = YES;
          self.typhoon_maxWindSpeedL.hidden = YES;
          self.typhoon_pressureTipsL.hidden = YES;
          self.typhoon_pressureL.hidden = YES;
          self.noTyphoon_tipsL.hidden = NO;
          
          self.typhoon_BackView.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/375*20, [UIScreen mainScreen].bounds.size.width/375*14 + k_Height_StatusBar+k_Height_NavContentBar, [UIScreen mainScreen].bounds.size.width/375*96, [UIScreen mainScreen].bounds.size.width/375*28);
          
      } else { // 有台风(有数据)
          self.typhoon_BackView.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/375*20, [UIScreen mainScreen].bounds.size.width/375*14 + k_Height_StatusBar+k_Height_NavContentBar, [UIScreen mainScreen].bounds.size.width/375*150, [UIScreen mainScreen].bounds.size.width/375*110);
          
          self.typhoon_longitudeTipsL.hidden = NO;
          self.typhoon_longitudeL.hidden = NO;
          self.typhoon_latitudeTipsL.hidden = NO;
          self.typhoon_latitudeL.hidden = NO;
          self.typhoon_maxWindSpeedTipsL.hidden = NO;
          self.typhoon_maxWindSpeedL.hidden = NO;
          self.typhoon_pressureTipsL.hidden = NO;
          self.typhoon_pressureL.hidden = NO;
          self.noTyphoon_tipsL.hidden = YES;
          
          if (self.raderMapDateModel.typhoon.count > 0 && self.raderMapDateModel.typhoon[0].routes.count > 0) {
              GWHomeRaderMap_TyphoonRoutesModel *routesModel = self.raderMapDateModel.typhoon[0].routes[self.raderMapDateModel.typhoon[0].routes.count-1];
              
              self.typhoon_longitudeL.text = [NSString stringWithFormat:@"%.f° E", routesModel.longitude];
              self.typhoon_latitudeL.text = [NSString stringWithFormat:@"%.f° N", routesModel.latitude];
              self.typhoon_maxWindSpeedL.text = [NSString stringWithFormat:@"%ld 米/秒", routesModel.maxWind];
              self.typhoon_pressureL.text = [NSString stringWithFormat:@"%ld  百帕", routesModel.pressure];
          }
      }
      
      if (self.groundOverlay != nil) {
          [self.mapView removeOverlay:self.groundOverlay]; // 点击台风的时候,删掉覆盖物层,在需要的时候重新创建
          self.groundOverlay = nil;
      }
      if (_timer) {
          [_timer invalidate]; // 停止,从Runlop中移除
          _timer = nil; // 放在内存溢出,重置为nil
      }
      
      /** 绘制台风轨迹: */
      [self setupTyphoonTrack];
    

    } else if (titleBut == self.aqiBut) {

    }
    }

  • (void)click_backCurrentPositionAction {
    // 回到(用户)当前位置
    // self.mapView.centerCoordinate = self.mapView.userLocation.location.coordinate;
    [self.mapView setCenterCoordinate:self.mapView.userLocation.location.coordinate animated:YES];
    [self gain_ClickMap_Request_WithLocationCoordinate:self.mapView.userLocation.location.coordinate];
    }

  • (void)click_playClimateChangeAction {
    // 气候变化(播放特效)

    if (self.currentImageArray.count <= 0 || self.itemCell >= self.currentImageArray.count) {
    return;
    }

    self.progress_playBut.selected = !self.progress_playBut.selected;

    if (self.progress_playBut.selected) { // 循环播放特效

      [self.timer setFireDate:[NSDate date]]; // 继续
    

    } else { // 暂停

      [self.timer setFireDate:[NSDate distantFuture]]; // 暂停
      
      UIImage *currentImage = self.currentImageArray[self.itemCell];
      
      if (self.groundOverlay != nil) {
          [self.mapView removeOverlay:self.groundOverlay]; // 点击台风的时候,删掉覆盖物层,在需要的时候重新创建
          self.groundOverlay = nil;
      }
      // 根据bounds值和icon生成GroundOverlay
      self.groundOverlay = [MAGroundOverlay groundOverlayWithBounds:self.coordinateBounds icon:currentImage];
    

// self.mapView.visibleMapRect = self.groundOverlay.boundingMapRect; // 可见区域, 设定的该范围可能会被调整为适合地图窗口显示的范围
[self.mapView addOverlay:self.groundOverlay];

    if (self.tempBut.selected) {
        
    } else if (self.rainBut.selected) {
        
    }
}

}

pragma mark -- 1、设置 地图 --

  • (void)setMapUI {

    _mapBackView = [[UIView alloc] initWithFrame:CGRectMake(0, k_Height_StatusBar + k_Height_NavContentBar, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - (k_Height_StatusBar + k_Height_NavContentBar + k_Height_TabBar))];
    [self.view addSubview:self.mapBackView];
    self.mapBackView.backgroundColor = RGBA(248, 246, 242, 1);

    ///是否打开地形图,默认NO. 注意:需在地图创建前设置
    // MAMapView.terrainEnabled = YES;

    ///初始化地图
    _mapView = [[MAMapView alloc] initWithFrame:self.mapBackView.bounds];
    ///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
    self.mapView.showsUserLocation = YES;
    self.mapView.userTrackingMode = MAUserTrackingModeFollow;
    self.mapView.delegate = self;
    self.mapView.zoomLevel = 18;
    self.mapView.rotationDegree = 0.f; ///设置地图旋转角度(逆时针为正向)
    self.mapView.cameraDegree = 0.f; ///设置地图相机角度(范围为[0.f, 60.f],但高于40度的角度需要在16级以上才能生效)
    // self.mapView.rotateEnabled = NO; ///是否支持旋转, 默认YES
    self.mapView.rotateCameraEnabled = NO; ///是否支持camera旋转(倾斜手势), 默认YES
    self.mapView.showsCompass = YES; ///是否显示指南针, 默认YES

///把地图添加至view
[self.mapBackView addSubview:self.mapView];
[self.mapView setZoomLevel:12 animated:YES];

// 标注:

// MAPointAnnotation *pointAnnotation = [[MAPointAnnotation alloc] init];

}

pragma mark -- <MAMapViewDelegate> --

/**

  • @brief 单击地图回调,返回经纬度
  • @param mapView 地图View
  • @param coordinate 经纬度
    */
  • (void)mapView:(MAMapView *)mapView didSingleTappedAtCoordinate:(CLLocationCoordinate2D)coordinate {
    NSLog(@"😝😝 点击地图的时候,返回的经度 = %.f,\n纬度 = %.f", coordinate.longitude, coordinate.latitude);
    // self.mapView.centerCoordinate = coordinate;
    // [self.mapView setCenterCoordinate:coordinate animated:YES]; // 设置当前地图的中心点,改变该值时,地图的比例尺级别不会发生变化

    if (self.tempBut.selected || self.rainBut.selected) {
    // 调用请求,获取该位置的天气信息

      [self gain_ClickMap_Request_WithLocationCoordinate:coordinate];
    

    }

}

pragma mark ========>>>>>>>>>> 方法【mapView:rendererForOverlay:】 <<<<<<<<<<<<==========

/// 实现<MAMapViewDelegate>协议中的mapView:rendererForOverlay:回调函数,以在地图上显示图片覆盖物。

  • (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id<MAOverlay>)overlay
    {
    if ([overlay isKindOfClass:[MAGroundOverlay class]]) { // 【气温】、【降水】overlay

      MAGroundOverlayRenderer *groundOverlayRenderer = [[MAGroundOverlayRenderer alloc] initWithGroundOverlay:overlay];
      return groundOverlayRenderer;
    

    } else if ([overlay isKindOfClass:[MAPolyline class]]) { // 【台风 轨迹线】overlay

      MAPolylineRenderer *polylineRenderer = [[MAPolylineRenderer alloc] initWithPolyline:overlay];
      
      polylineRenderer.is3DArrowLine = NO;///设置是否显示3d箭头线, 默认为NO。如果设置为YES,则为3d箭头线。
      polylineRenderer.sideColor = RGBA(31, 127, 251, 1);
      polylineRenderer.showRangeEnabled = NO; ///是否启用显示范围,YES启用,不启用时展示全路径
      
      polylineRenderer.lineWidth    = 3.f; ///笔触宽度
      polylineRenderer.fillColor = UIColor.clearColor; ///填充颜色
      polylineRenderer.strokeColor  = RGBA(31, 127, 251, 1);///笔触颜色
      polylineRenderer.lineJoinType = kMALineJoinRound;// 接头
      polylineRenderer.lineCapType  = kMALineCapArrow;  // 线端(带箭头)
      
      polylineRenderer.miterLimit = 20.f;
      polylineRenderer.lineDashType = kMALineDashTypeNone; /// 虚线样式(已经走过的路线的画实线,预测的画虚线)
      
      return polylineRenderer;
    

    }

    return nil;
    }

pragma mark -- 2、持续定位 --

  • (void)settingMapLocation {

    _locationManager = [[AMapLocationManager alloc] init];
    self.locationManager.delegate = self;
    }

  • (void)startSerialLocation
    {
    // (持续)开始定位
    [self.locationManager startUpdatingLocation];
    }

  • (void)stopSerialLocation
    {
    // 停止定位
    [self.locationManager stopUpdatingLocation];
    }

pragma mark -- 地位代理方法、回调 <AMapLocationManagerDelegate> ==

/**

  • @brief (连续定位回调函数).注意:如果实现了本方法,则定位信息不会通过amapLocationManager:didUpdateLocation:方法回调。
  • @param manager 定位 AMapLocationManager 类。
  • @param location 定位结果。
  • @param reGeocode 逆地理信息。
    */
    //接收位置更新,实现AMapLocationManagerDelegate代理的amapLocationManager:didUpdateLocation方法,处理位置更新
  • (void)amapLocationManager:(AMapLocationManager *)manager didUpdateLocation:(CLLocation *)location reGeocode:(AMapLocationReGeocode *)reGeocode {

    NSLog(@"location:{纬度lat:%f; 经度lon:%f; 精确度accuracy:%f}", location.coordinate.latitude, location.coordinate.longitude, location.horizontalAccuracy);
    if (reGeocode)
    {
    NSLog(@"reGeocode:%@", reGeocode);
    }
    }

/**

  • @brief 当定位发生错误时,会调用代理的此方法。
  • @param manager 定位 AMapLocationManager 类。
  • @param error 返回的错误,参考 CLError 。
    */
  • (void)amapLocationManager:(AMapLocationManager *)manager didFailWithError:(NSError *)error {
    NSLog(@"😂😂 报错:error ====>>>> %@", error);
    }

pragma mark ****** 3、网络请求:返回多张图片 (根据东北角、西南角两个点的经纬度,覆盖到地图上) ******

  • (void)gainTempAndRainImages_Request {
    [BRNetworkHepler getWithUrl:@"https://www.baidu.com.8769/more/images" params:nil headers:nil success:^(GWHttpBaseResponseModel *responseObject, NSString *message) {
    NSInteger code = responseObject.code;
    if (code == 200) {
    GWHomeRaderMap_DataModel *dateModel = [GWHomeRaderMap_DataModel modelWithDictionary:responseObject.data];

          // 处理一下时间(增加一个时间,格式:MM-dd HH:mm)
          for (int i=0; i < dateModel.temp.list.count; i++) {
              GWHomeRaderMap_TempListModel *model = dateModel.temp.list[i];
              dateModel.temp.list[i].timeStr = [LCM_Tool TimeStampTransform:model.timestamp andstyle:@"MM-dd HH:mm"];
          }
          for (int i=0; i < dateModel.precip.list.count; i++) {
              GWHomeRaderMap_PrecipListModel *model = dateModel.precip.list[i];
              dateModel.precip.list[i].timeStr = [LCM_Tool TimeStampTransform:model.timestamp andstyle:@"MM-dd HH:mm"];
          }
          
          self.raderMapDateModel = dateModel;
          
          
          NSMutableArray *tempImgs = [NSMutableArray arrayWithCapacity:0];
          NSMutableArray *rainImgs = [NSMutableArray arrayWithCapacity:0];
          for (GWHomeRaderMap_TempListModel *tempListModel in self.raderMapDateModel.temp.list) {
              
              NSData *tempData = [NSData dataWithContentsOfURL:[NSURL URLWithString:tempListModel.url]];
              UIImage *image = [UIImage imageWithData:tempData];
              [tempImgs addObject:image];
          }
          for (GWHomeRaderMap_TempListModel *rainListModel in self.raderMapDateModel.precip.list) {
              
              NSData *rainData = [NSData dataWithContentsOfURL:[NSURL URLWithString:rainListModel.url]];
              UIImage *image = [UIImage imageWithData:rainData];
              [rainImgs addObject:image];
          }
          
          self.tempImageArray = [tempImgs copy];
          self.rainImageArray = [rainImgs copy];
          
          self.currentImageArray = [self.tempImageArray copy];
          
          
          if (self.mapView) {
              
              [self showTemp_Action];
              
              self.progress_BackView.hidden = NO;
              self.progress_tipsL.hidden = NO;
          }
          
      } else {
          [LCM_AlertViewFactory showToastWithMessage:responseObject.msg];
      }
    

    } failure:^(NSError *error, NSString *message) {
    NSLog(@"error =====>>>> %@", error);
    NSLog(@"message ---->> %@", message);
    }];
    }

pragma mark -- NSTimer: 将图片 一遍遍的 循环展示(轮询) --

  • (void)showTemp_Action {
    // 温度 图片

    if (self.raderMapDateModel != nil) {

      if (_timer) {
          [_timer invalidate];
          _timer = nil;
      }
      
      if (self.groundOverlay != nil) {
          [self.mapView removeOverlay:self.groundOverlay]; // 点击台风的时候,删掉覆盖物层,在需要的时候重新创建
          self.groundOverlay = nil;
      }
      if (self.commonPolyline != nil) {
          [self.mapView removeOverlay:self.commonPolyline]; // 删除 绘制折线overlay
          self.commonPolyline = nil;
      }
      for (MAAnnotationMoveAnimation *animation in [self.typhoon_AnimatedAnnotation allMoveAnimations]) {
          [animation cancel];
      }
      if (self.typhoon_AnimatedAnnotation != nil) {
          [self.mapView removeAnnotation:self.typhoon_AnimatedAnnotation]; // 删除 【点平滑移动】(这里特指 台风的图片)overlay
          self.typhoon_AnimatedAnnotation = nil;
      }
    

// if (self.typhoon_PointAnnotation != nil) {
// [self.mapView removeAnnotation:self.typhoon_PointAnnotation]; // 删除 【点标记📌】(这里特指 台风的图片)overlay
// self.typhoon_PointAnnotation = nil;
// }
if (self.locatinWeather_AnimatedAnnotation != nil) {
[self.mapView removeAnnotation:self.locatinWeather_AnimatedAnnotation]; // 删除 【自定义气泡】Annotation
self.locatinWeather_AnimatedAnnotation = nil;
}

    self.currentImageArray = [self.tempImageArray copy];
    
    [self create_TempTimeline];
    self.progress_playBut.selected = NO;
    self.progress_beginTimeL.text = [NSString stringWithFormat:@"%@", self.raderMapDateModel.temp.list[0].timeStr];
    self.progress_endTimeL.text = [NSString stringWithFormat:@"%@", self.raderMapDateModel.temp.list[self.raderMapDateModel.temp.list.count-1].timeStr];
    self.progress_tipsL.text = self.raderMapDateModel.temp.list[0].timeStr;
    self.progress_tipsL.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/375*(15+40 -30), [UIScreen mainScreen].bounds.size.height - k_Height_TabBar - [UIScreen mainScreen].bounds.size.width/375*(19+44+22), [UIScreen mainScreen].bounds.size.width/375*60, [UIScreen mainScreen].bounds.size.width/375*22);
    
    // 东北角、西南角的经纬度
    NSArray *areaArray = [self.raderMapDateModel.temp.area componentsSeparatedByString:@","];
    CGFloat southLatitude = [areaArray[0] floatValue];
    CGFloat southLongitude = [areaArray[1] floatValue];
    CGFloat northLatitude = [areaArray[2] floatValue];
    CGFloat northLongitude = [areaArray[3] floatValue];
    
    
    
    // 【气温】图片覆盖物:
    // 前:东北角,后:西南角
    MACoordinateBounds coordinateBounds = MACoordinateBoundsMake(CLLocationCoordinate2DMake(northLatitude, northLongitude),CLLocationCoordinate2DMake(southLatitude, southLongitude));
    self.coordinateBounds = coordinateBounds;
    
    UIImage *tempImg = self.tempImageArray[0];
    
    if (self.groundOverlay == nil) {
        MAGroundOverlay *groundOverlay = [MAGroundOverlay groundOverlayWithBounds:coordinateBounds icon:tempImg];
        [self.mapView addOverlay:groundOverlay];

// self.mapView.visibleMapRect = groundOverlay.boundingMapRect;///可见区域, 设定的该范围可能会被调整为适合地图窗口显示的范围
self.groundOverlay = groundOverlay;
} else {
// 之后,切换【气温】和【降水】时,更新MAGroundOverlay
[self.groundOverlay setGroundOverlayWithBounds:coordinateBounds icon:tempImg];
}
// 之后,切换【气温】和【降水】时,更新MAGroundOverlay
// [self.groundOverlay setGroundOverlayWithBounds:coordinateBounds icon:[UIImage imageNamed:@""]];

    self.itemCell = 0;
    
    _timer = [NSTimer scheduledTimerWithTimeInterval:0.14 target:self selector:@selector(startIconRunLoop) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];
    
    [self.timer setFireDate:[NSDate distantFuture]]; // 暂停(需,手动控制开关,所以暂时不立即启动)

// [_timer fire]; // 立即 启动

} else {
    if (_timer) {
        [_timer invalidate]; // 停止,从Runlop中移除
        _timer = nil; // 放在内存溢出,重置为nil
    }
}

}

  • (void)showRain_Action {
    // 降水 图片

    if (self.raderMapDateModel != nil) {

      if (_timer) {
          [_timer invalidate]; // 停止,从Runlop中移除
          _timer = nil; // 放在内存溢出,重置为nil
      }
      
      if (self.groundOverlay != nil) {
          [self.mapView removeOverlay:self.groundOverlay]; // 点击台风的时候,删掉覆盖物层,在需要的时候重新创建
          self.groundOverlay = nil;
      }
      if (self.commonPolyline != nil) {
          [self.mapView removeOverlay:self.commonPolyline]; // 删除 绘制折线overlay
          self.commonPolyline = nil;
      }
      for (MAAnnotationMoveAnimation *animation in [self.typhoon_AnimatedAnnotation allMoveAnimations]) {
          [animation cancel]; // 结束动画
      }
      
      if (self.typhoon_AnimatedAnnotation != nil) {
          [self.mapView removeAnnotation:self.typhoon_AnimatedAnnotation]; // 删除 【点平滑移动】(这里特指 台风的图片)overlay
          self.typhoon_AnimatedAnnotation = nil;
      }
    

// if (self.typhoon_PointAnnotation != nil) {
// [self.mapView removeAnnotation:self.typhoon_PointAnnotation]; // 删除 【点标记📌】(这里特指 台风的图片)overlay
// self.typhoon_PointAnnotation = nil;
// }
if (self.locatinWeather_AnimatedAnnotation != nil) {
[self.mapView removeAnnotation:self.locatinWeather_AnimatedAnnotation]; // 删除 【自定义气泡】Annotation
self.locatinWeather_AnimatedAnnotation = nil;
}

    self.currentImageArray = [self.rainImageArray copy];
    
    [self create_TempTimeline];
    self.progress_playBut.selected = NO;
    self.progress_beginTimeL.text = [NSString stringWithFormat:@"%@", self.raderMapDateModel.precip.list[0].timeStr];
    self.progress_endTimeL.text = [NSString stringWithFormat:@"%@", self.raderMapDateModel.precip.list[self.raderMapDateModel.precip.list.count-1].timeStr];
    self.progress_tipsL.text = self.raderMapDateModel.precip.list[0].timeStr;
    self.progress_tipsL.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/375*(15+40 -30), [UIScreen mainScreen].bounds.size.height - k_Height_TabBar - [UIScreen mainScreen].bounds.size.width/375*(19+44+22), [UIScreen mainScreen].bounds.size.width/375*60, [UIScreen mainScreen].bounds.size.width/375*22);
    
    // 东北角、西南角的经纬度
    NSArray *areaArray = [self.raderMapDateModel.precip.area componentsSeparatedByString:@","];
    CGFloat southLatitude = [areaArray[0] floatValue];
    CGFloat southLongitude = [areaArray[1] floatValue];
    CGFloat northLatitude = [areaArray[2] floatValue];
    CGFloat northLongitude = [areaArray[3] floatValue];
    
    
    // 【气温】图片覆盖物:
    // 前:东北角,后:西南角
    MACoordinateBounds coordinateBounds = MACoordinateBoundsMake(CLLocationCoordinate2DMake(northLatitude, northLongitude),CLLocationCoordinate2DMake(southLatitude, southLongitude));
    self.coordinateBounds = coordinateBounds;
    
    UIImage *tempImg = self.rainImageArray[0];
    
    if (self.groundOverlay == nil) {
        MAGroundOverlay *groundOverlay = [MAGroundOverlay groundOverlayWithBounds:coordinateBounds icon:tempImg];
        [self.mapView addOverlay:groundOverlay];

// self.mapView.visibleMapRect = groundOverlay.boundingMapRect;///可见区域, 设定的该范围可能会被调整为适合地图窗口显示的范围
self.groundOverlay = groundOverlay;
} else {
// 之后,切换【气温】和【降水】时,更新MAGroundOverlay
[self.groundOverlay setGroundOverlayWithBounds:coordinateBounds icon:tempImg];
}

    self.itemCell = 0;
    _timer = [NSTimer scheduledTimerWithTimeInterval:0.14 target:self selector:@selector(startIconRunLoop) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];
    
    [self.timer setFireDate:[NSDate distantFuture]]; // 暂停(需,手动控制开关)

// [_timer fire]; // 立即 启动

} else {
    if (_timer) {
        [_timer invalidate]; // 停止,从Runlop中移除
        _timer = nil; // 放在内存溢出,重置为nil
    }
}

}

// 多张图片,使用NSTimer 循环

  • (void)startIconRunLoop {

    if (self.itemCell < self.currentImageArray.count && self.currentImageArray.count > 0) {

      UIImage *currentImage = self.currentImageArray[self.itemCell];
      NSLog(@"☺️☺️☺️☺️ self.itemCell = %ld", self.itemCell);
      
      
      if (self.tempBut.selected || self.rainBut.selected) {
          
          if (self.groundOverlay != nil) {
              [self.mapView removeOverlay:self.groundOverlay]; // 点击台风的时候,删掉覆盖物层,在需要的时候重新创建
              self.groundOverlay = nil;
          }
          // 根据bounds值和icon生成GroundOverlay
          self.groundOverlay = [MAGroundOverlay groundOverlayWithBounds:self.coordinateBounds icon:currentImage];
    

// self.mapView.visibleMapRect = self.groundOverlay.boundingMapRect; // 可见区域, 设定的该范围可能会被调整为适合地图窗口显示的范围
[self.mapView addOverlay:self.groundOverlay];

        /** 【天气 标注气泡】 */
        if (self.locatinWeather_AnimatedAnnotation != nil) {
            [self.mapView removeAnnotation:self.locatinWeather_AnimatedAnnotation]; // 删除 【自定义气泡】Annotation
            self.locatinWeather_AnimatedAnnotation = nil;
        }
        if (self.locatinWeather_AnimatedAnnotation == nil && self.locationWeatherModel != nil) {
            
            
            MAAnimatedAnnotation *locatinWeather_AnimatedAnnotation = [[MAAnimatedAnnotation alloc] init];
            locatinWeather_AnimatedAnnotation.coordinate = CLLocationCoordinate2DMake(self.locationWeatherModel.latitude, self.locationWeatherModel.longitude); // 初始位置

// locatinWeather_AnimatedAnnotation.title = self.raderMapDateModel.typhoon[0].nameCn;
self.locatinWeather_AnimatedAnnotation = locatinWeather_AnimatedAnnotation;
[self.mapView addAnnotation:self.locatinWeather_AnimatedAnnotation];
[self.mapView selectAnnotation:self.locatinWeather_AnimatedAnnotation animated:YES]; // 选中状态(显示标注view)

        }

// else {
// self.locatinWeather_AnimatedAnnotation.coordinate = CLLocationCoordinate2DMake(self.locationWeatherModel.latitude, self.locationWeatherModel.longitude); // 初始位置
// [self.mapView selectAnnotation:self.locatinWeather_AnimatedAnnotation animated:YES];
// }

        CGFloat lineWidth = [UIScreen mainScreen].bounds.size.width/375*225/(self.currentImageArray.count -1);
        
        self.progress_currentLineView.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/375*(40-1) + lineWidth*self.itemCell, 0, [UIScreen mainScreen].bounds.size.width/375*2, [UIScreen mainScreen].bounds.size.width/375*22);
        
        
        if (([UIScreen mainScreen].bounds.size.width/375*(15 + 40 - 30) + lineWidth*self.itemCell) < [UIScreen mainScreen].bounds.size.width/375*(15+40 -30)) {
            self.progress_tipsL.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/375*(15 + 40 -30), [UIScreen mainScreen].bounds.size.height - k_Height_TabBar - [UIScreen mainScreen].bounds.size.width/375*(19+44+22), [UIScreen mainScreen].bounds.size.width/375*60, [UIScreen mainScreen].bounds.size.width/375*22);
        } else if (([UIScreen mainScreen].bounds.size.width/375*(15 + 40 - 30) + lineWidth*self.itemCell) > [UIScreen mainScreen].bounds.size.width/375*(15+40 +225 -30)) {
            self.progress_tipsL.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/375*(15 + 40 +225-30), [UIScreen mainScreen].bounds.size.height - k_Height_TabBar - [UIScreen mainScreen].bounds.size.width/375*(19+44+22), [UIScreen mainScreen].bounds.size.width/375*60, [UIScreen mainScreen].bounds.size.width/375*22);
        } else {
            self.progress_tipsL.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/375*(15 + 40 - 30) + lineWidth*self.itemCell, [UIScreen mainScreen].bounds.size.height - k_Height_TabBar - [UIScreen mainScreen].bounds.size.width/375*(19+44+22), [UIScreen mainScreen].bounds.size.width/375*60, [UIScreen mainScreen].bounds.size.width/375*22);
        }
        
        if (self.tempBut.selected) {
            self.progress_tipsL.text = self.raderMapDateModel.temp.list[self.itemCell].timeStr;
        } else if (self.rainBut.selected) {
            self.progress_tipsL.text = self.raderMapDateModel.precip.list[self.itemCell].timeStr;
        }
        

    } else if (self.typhoonBut.selected) {
        
    }
    
    self.itemCell = self.itemCell + 1;
    
} else {

    self.itemCell = 0;
    
    [self startIconRunLoop];
}

}

  • (void)dealloc {
    [_timer invalidate]; // 停止,从Runlop中移除
    _timer = nil; // 放在内存溢出,重置为nil
    }

pragma mark -- -- -- -- 点击【气温】、【降水】时,或点击【tabBar雷达】时,有数据的情况下:创建 气温“时间刻度” -- -- -- --

  • (void)create_TempTimeline {

    // 每个小格子的宽度:(因为,无论是“气温”还是“降水”时,第一个刻度和最后一个刻度的竖线,位置都不边,计算单个小格子的宽度下边这个,第一个格子前一半+最后一个格子的后一半 = 一个整格子)
    CGFloat lineWidth = [UIScreen mainScreen].bounds.size.width/375*225/(self.currentImageArray.count -1);

    [self.progress_lineBackView removeAllSubviews]; // 删除所有子view(删除时间刻度,重新创建)
    self.progress_lineBackView.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/375(40) - lineWidth/2, 0, [UIScreen mainScreen].bounds.size.width/375225 + lineWidth, [UIScreen mainScreen].bounds.size.width/375*44);
    self.progress_lineBackView.backgroundColor = UIColor.clearColor;//RGBA(212, 229, 225, 1);

for (int i=0; i < self.currentImageArray.count; i++) {
    
    // 分成一块块的小格子,时间刻度在每个块的中间(因为 每次 个数和宽度可能会发生变化,所以最好每次都重新创建)
    
    UIView  *lineBackView = [[UIView alloc] initWithFrame:CGRectMake(0 + lineWidth*i, 0, lineWidth, [UIScreen mainScreen].bounds.size.width/375*11)];
    lineBackView.backgroundColor = UIColor.clearColor;//RGBA(255, 193, 188, 0.5);
    [self.progress_lineBackView addSubview:lineBackView];
    
    UIView  *lineView = [[UIView alloc] initWithFrame:CGRectMake((lineWidth/2 + lineWidth*i) - [UIScreen mainScreen].bounds.size.width/375*0.5, 0, 1, [UIScreen mainScreen].bounds.size.width/375*11)];
    lineView.backgroundColor = RGBA(193, 162, 122, 1);
    [self.progress_lineBackView addSubview:lineView];
    
}

}

pragma mark -- -- -- -- 时间刻度轴:手指滑动 Touch 触摸 -- -- -- --

  • (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event {
    // 手指触摸 开始

    UITouch *touch = touches.anyObject;
    CGPoint point = [touch locationInView:self.progress_view];

    NSLog(@"手指触摸 开始: 手指所在 折线图📈上的位置 point.X ==== %f,\n point.Y ==== %f", point.x, point.y);

    // 每个时间刻度的距离
    CGFloat lineWidth = [UIScreen mainScreen].bounds.size.width/375*225/(self.currentImageArray.count -1);
    CGFloat touch_Point_X = point.x;

    if (CGRectContainsPoint(self.progress_view.frame, point) && point.x >= ([UIScreen mainScreen].bounds.size.width/37540 - lineWidth/2) && point.x <= ([UIScreen mainScreen].bounds.size.width/375(40 + 225) + lineWidth/2)) {

    NSInteger indexItem = (touch_Point_X - [UIScreen mainScreen].bounds.size.width/375*40 + lineWidth/2) / lineWidth;
    
    self.itemCell = indexItem;
    
    UIImage *currentImage = self.currentImageArray[self.itemCell];
    NSLog(@"☺️☺️☺️☺️ self.itemCell = %ld", self.itemCell);
    // 显示该位置的刻度
    if (self.groundOverlay != nil) {
        [self.mapView removeOverlay:self.groundOverlay]; // 点击台风的时候,删掉覆盖物层,在需要的时候重新创建
        self.groundOverlay = nil;
    }
    // 根据bounds值和icon生成GroundOverlay
    self.groundOverlay = [MAGroundOverlay groundOverlayWithBounds:self.coordinateBounds icon:currentImage];

// self.mapView.visibleMapRect = self.groundOverlay.boundingMapRect;
[self.mapView addOverlay:self.groundOverlay];

    CGFloat lineWidth = [UIScreen mainScreen].bounds.size.width/375*225/(self.currentImageArray.count -1);
    
    self.progress_currentLineView.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/375*(40-1) + lineWidth*self.itemCell, 0, [UIScreen mainScreen].bounds.size.width/375*2, [UIScreen mainScreen].bounds.size.width/375*22);
    
    if (([UIScreen mainScreen].bounds.size.width/375*(15 + 40 - 30) + lineWidth*self.itemCell) < [UIScreen mainScreen].bounds.size.width/375*(15+40 -30)) {
        self.progress_tipsL.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/375*(15 + 40 -30), [UIScreen mainScreen].bounds.size.height - k_Height_TabBar - [UIScreen mainScreen].bounds.size.width/375*(19+44+22), [UIScreen mainScreen].bounds.size.width/375*60, [UIScreen mainScreen].bounds.size.width/375*22);
    } else if (([UIScreen mainScreen].bounds.size.width/375*(15 + 40 - 30) + lineWidth*self.itemCell) > [UIScreen mainScreen].bounds.size.width/375*(15+40 +225 -30)) {
        self.progress_tipsL.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/375*(15 + 40 +225-30), [UIScreen mainScreen].bounds.size.height - k_Height_TabBar - [UIScreen mainScreen].bounds.size.width/375*(19+44+22), [UIScreen mainScreen].bounds.size.width/375*60, [UIScreen mainScreen].bounds.size.width/375*22);
    } else {
        self.progress_tipsL.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/375*(15 + 40 - 30) + lineWidth*self.itemCell, [UIScreen mainScreen].bounds.size.height - k_Height_TabBar - [UIScreen mainScreen].bounds.size.width/375*(19+44+22), [UIScreen mainScreen].bounds.size.width/375*60, [UIScreen mainScreen].bounds.size.width/375*22);
    }
    
    if (self.tempBut.selected) {
        self.progress_tipsL.text = self.raderMapDateModel.temp.list[self.itemCell].timeStr;
    } else if (self.rainBut.selected) {
        self.progress_tipsL.text = self.raderMapDateModel.precip.list[self.itemCell].timeStr;
    } else {
        
    }
    
    /** 【天气 标注气泡】 */
    if (self.locatinWeather_AnimatedAnnotation != nil) {
        [self.mapView removeAnnotation:self.locatinWeather_AnimatedAnnotation]; // 删除 【自定义气泡】Annotation
        self.locatinWeather_AnimatedAnnotation = nil;
    }
    if (self.locatinWeather_AnimatedAnnotation == nil && self.locationWeatherModel != nil) {
        
        
        MAAnimatedAnnotation *locatinWeather_AnimatedAnnotation = [[MAAnimatedAnnotation alloc] init];
        locatinWeather_AnimatedAnnotation.coordinate = CLLocationCoordinate2DMake(self.locationWeatherModel.latitude, self.locationWeatherModel.longitude); // 初始位置

// locatinWeather_AnimatedAnnotation.title = self.raderMapDateModel.typhoon[0].nameCn;
self.locatinWeather_AnimatedAnnotation = locatinWeather_AnimatedAnnotation;
[self.mapView addAnnotation:self.locatinWeather_AnimatedAnnotation];
[self.mapView selectAnnotation:self.locatinWeather_AnimatedAnnotation animated:YES]; // 选中状态(显示标注view)

    }
    
    NSLog(@"😆 触摸 对了");
} else {
    NSLog(@"触摸 错错错❎");
}

}

  • (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event {
    // 手指触摸 移动

    // iOS 怎么样获取手指在view上滑动的起点坐标与终点坐标
    UITouch *touch = touches.anyObject;
    CGPoint point = [touch locationInView:self.progress_view];

    NSLog(@"移动中: 手指所在 折线图📈上的位置 point.X ==== %f,\n point.Y ==== %f", point.x, point.y);

    // 每个时间刻度的距离
    CGFloat lineWidth = [UIScreen mainScreen].bounds.size.width/375*225/(self.currentImageArray.count -1);
    CGFloat touch_Point_X = point.x;

    // 如果矩形不为null,或空,并且该点位于矩形内,返回YES,在范围外面 返回NO
    if (CGRectContainsPoint(self.progress_view.frame, point) && point.x >= ([UIScreen mainScreen].bounds.size.width/37540 - lineWidth/2) && point.x <= ([UIScreen mainScreen].bounds.size.width/375(40 + 225) + lineWidth/2)) {

    NSInteger indexItem = (touch_Point_X - [UIScreen mainScreen].bounds.size.width/375*40 + lineWidth/2) / lineWidth;
    
    self.itemCell = indexItem;
    
    UIImage *currentImage = self.currentImageArray[self.itemCell];
    NSLog(@"☺️☺️☺️☺️ self.itemCell = %ld", self.itemCell);
    // 显示该位置的刻度
    if (self.groundOverlay != nil) {
        [self.mapView removeOverlay:self.groundOverlay]; // 点击台风的时候,删掉覆盖物层,在需要的时候重新创建
        self.groundOverlay = nil;
    }
    // 根据bounds值和icon生成GroundOverlay
    self.groundOverlay = [MAGroundOverlay groundOverlayWithBounds:self.coordinateBounds icon:currentImage];

// self.mapView.visibleMapRect = self.groundOverlay.boundingMapRect;
[self.mapView addOverlay:self.groundOverlay];

    CGFloat lineWidth = [UIScreen mainScreen].bounds.size.width/375*225/(self.currentImageArray.count -1);
    
    self.progress_currentLineView.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/375*(40-1) + lineWidth*self.itemCell, 0, [UIScreen mainScreen].bounds.size.width/375*2, [UIScreen mainScreen].bounds.size.width/375*22);
    
    
    if (([UIScreen mainScreen].bounds.size.width/375*(15 + 40 - 30) + lineWidth*self.itemCell) < [UIScreen mainScreen].bounds.size.width/375*(15+40 -30)) {
        self.progress_tipsL.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/375*(15 + 40 -30), [UIScreen mainScreen].bounds.size.height - k_Height_TabBar - [UIScreen mainScreen].bounds.size.width/375*(19+44+22), [UIScreen mainScreen].bounds.size.width/375*60, [UIScreen mainScreen].bounds.size.width/375*22);
    } else if (([UIScreen mainScreen].bounds.size.width/375*(15 + 40 - 30) + lineWidth*self.itemCell) > [UIScreen mainScreen].bounds.size.width/375*(15+40 +225 -30)) {
        self.progress_tipsL.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/375*(15 + 40 +225-30), [UIScreen mainScreen].bounds.size.height - k_Height_TabBar - [UIScreen mainScreen].bounds.size.width/375*(19+44+22), [UIScreen mainScreen].bounds.size.width/375*60, [UIScreen mainScreen].bounds.size.width/375*22);
    } else {
        self.progress_tipsL.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/375*(15 + 40 - 30) + lineWidth*self.itemCell, [UIScreen mainScreen].bounds.size.height - k_Height_TabBar - [UIScreen mainScreen].bounds.size.width/375*(19+44+22), [UIScreen mainScreen].bounds.size.width/375*60, [UIScreen mainScreen].bounds.size.width/375*22);
    }
    
    if (self.tempBut.selected) {
        self.progress_tipsL.text = self.raderMapDateModel.temp.list[self.itemCell].timeStr;
    } else if (self.rainBut.selected) {
        self.progress_tipsL.text = self.raderMapDateModel.precip.list[self.itemCell].timeStr;
    } else {
        
    }
    
    /** 【天气 标注气泡】 */
    if (self.locatinWeather_AnimatedAnnotation != nil) {
        [self.mapView removeAnnotation:self.locatinWeather_AnimatedAnnotation]; // 删除 【自定义气泡】Annotation
        self.locatinWeather_AnimatedAnnotation = nil;
    }
    if (self.locatinWeather_AnimatedAnnotation == nil && self.locationWeatherModel != nil) {
        
        
        MAAnimatedAnnotation *locatinWeather_AnimatedAnnotation = [[MAAnimatedAnnotation alloc] init];
        locatinWeather_AnimatedAnnotation.coordinate = CLLocationCoordinate2DMake(self.locationWeatherModel.latitude, self.locationWeatherModel.longitude); // 初始位置

// locatinWeather_AnimatedAnnotation.title = self.raderMapDateModel.typhoon[0].nameCn;
self.locatinWeather_AnimatedAnnotation = locatinWeather_AnimatedAnnotation;
[self.mapView addAnnotation:self.locatinWeather_AnimatedAnnotation];
[self.mapView selectAnnotation:self.locatinWeather_AnimatedAnnotation animated:YES]; // 选中状态(显示标注view)

    }
    
    NSLog(@"😆 触摸 对了");
} else {
    NSLog(@"触摸 错错错❎");
}

}

  • (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event {
    // 手指触摸 结束
    NSLog(@"手指触摸 结束");

}

  • (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event {
    // 取消触摸时
    NSLog(@"取消触摸");
    }

pragma mark ****** 4、台风:轨迹 “高德地图:【绘制折线】、

pragma mark ------------ 【设置UI】

  • (void)setupUI {

    _tempBut = [UIButton buttonWithType:UIButtonTypeCustom];
    [tempBut setBackgroundImage:[UIImage imageNamed:@"raderMap气温_select_icon"] forState:UIControlStateSelected];
    [tempBut setBackgroundImage:[UIImage imageNamed:@"raderMap气温_noSelect_icon"] forState:UIControlStateNormal];
    _tempBut.adjustsImageWhenHighlighted = NO; // 下面的背景图片可以保证图片不变灰
    [self.navigationBar addSubview:self.tempBut];
    [self.tempBut makeConstraints:^(MASConstraintMaker make) {
    make.centerY.equalTo(self.navigationBar);
    make.left.mas_equalTo(self.navigationBar.mas_left).offset([UIScreen mainScreen].bounds.size.width/375
    15);
    make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width/37593);
    make.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375
    44);
    }];
    [self.tempBut addTarget:self action:@selector(clickRaderMapBotton:) forControlEvents:UIControlEventTouchUpInside];

    _rainBut = [UIButton buttonWithType:UIButtonTypeCustom];
    [rainBut setBackgroundImage:[UIImage imageNamed:@"raderMap降水_select_icon"] forState:UIControlStateSelected];
    [rainBut setBackgroundImage:[UIImage imageNamed:@"raderMap降水_noSelect_icon"] forState:UIControlStateNormal];
    _rainBut.adjustsImageWhenHighlighted = NO; // 下面的背景图片可以保证图片不变灰
    [self.navigationBar addSubview:self.rainBut];
    [self.rainBut makeConstraints:^(MASConstraintMaker make) {
    make.centerY.equalTo(self.navigationBar);
    make.centerX.equalTo(self.navigationBar);
    make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width/375
    93);
    make.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*44);
    }];
    [self.rainBut addTarget:self action:@selector(clickRaderMapBotton:) forControlEvents:UIControlEventTouchUpInside];

    _typhoonBut = [UIButton buttonWithType:UIButtonTypeCustom];
    [typhoonBut setBackgroundImage:[UIImage imageNamed:@"raderMap台风_select_icon"] forState:UIControlStateSelected];
    [typhoonBut setBackgroundImage:[UIImage imageNamed:@"raderMap台风_noSelect_icon"] forState:UIControlStateNormal];
    _typhoonBut.adjustsImageWhenHighlighted = NO; // 下面的背景图片可以保证图片不变灰
    [self.navigationBar addSubview:self.typhoonBut];
    [self.typhoonBut makeConstraints:^(MASConstraintMaker make) {
    make.centerY.equalTo(self.navigationBar);
    make.right.mas_equalTo(self.navigationBar.mas_right).offset(-[UIScreen mainScreen].bounds.size.width/375
    15);
    make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width/37593);
    make.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375
    44);
    }];
    [self.typhoonBut addTarget:self action:@selector(clickRaderMapBotton:) forControlEvents:UIControlEventTouchUpInside];

self.tempBut.selected = YES;
self.rainBut.selected = NO;
self.typhoonBut.selected = NO;

}

/** 布局:(气温+降水)自定义功能 */

  • (void)setupTempAndRainOtherFunction {

    /// 气候等级
    _climateRank_BackView = [[UIView alloc] init];
    self.climateRank_BackView.backgroundColor = RGBA(248, 246, 242, 1);
    self.climateRank_BackView.layer.cornerRadius = [UIScreen mainScreen].bounds.size.width/37526/2;
    self.climateRank_BackView.layer.shadowColor = RGBA(0, 0, 0, 0.12).CGColor;
    self.climateRank_BackView.layer.shadowOffset = CGSizeMake(0, 0);
    self.climateRank_BackView.layer.shadowRadius = [UIScreen mainScreen].bounds.size.width/375
    8;
    self.climateRank_BackView.layer.shadowOpacity = 1;
    [self.view addSubview:self.climateRank_BackView];
    [self.climateRank_BackView makeConstraints:^(MASConstraintMaker make) {
    make.top.mas_equalTo(self.view.mas_top).offset(k_Height_StatusBar+k_Height_NavContentBar + [UIScreen mainScreen].bounds.size.width/375
    14);
    make.left.mas_equalTo(self.view.mas_left).offset([UIScreen mainScreen].bounds.size.width/37520);
    make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width/375
    173);
    make.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*26);
    }];

    _climateRank_Img = [[UIImageView alloc] init];
    self.climateRank_Img.image = [UIImage imageNamed:@"raderMap_TempRankColor_icon"];
    [self.climateRank_BackView addSubview:self.climateRank_Img];
    [self.climateRank_Img makeConstraints:^(MASConstraintMaker make) {
    make.center.equalTo(self.climateRank_BackView);
    make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width/375
    115);
    make.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*6);
    }];

    _climateRank_minTipsL = [[UILabel alloc] init];
    _climateRank_minTipsL.text = @"-40°";
    _climateRank_minTipsL.textColor = RGBA(0, 0, 0, 0.5);
    _climateRank_minTipsL.textAlignment = NSTextAlignmentLeft;
    _climateRank_minTipsL.font = FontSourceHanSerifCN_Medium([UIScreen mainScreen].bounds.size.width/375*10);
    [self.climateRank_BackView addSubview:self.climateRank_minTipsL];
    [self.climateRank_minTipsL makeConstraints:^(MASConstraintMaker make) {
    make.centerY.equalTo(self.climateRank_BackView);
    make.left.mas_equalTo(self.climateRank_BackView.mas_left).offset([UIScreen mainScreen].bounds.size.width/375
    8);
    }];

    _climateRank_maxTipsL = [[UILabel alloc] init];
    _climateRank_maxTipsL.text = @"40°";
    _climateRank_maxTipsL.textColor = RGBA(0, 0, 0, 0.5);
    _climateRank_maxTipsL.textAlignment = NSTextAlignmentRight;
    _climateRank_maxTipsL.font = FontSourceHanSerifCN_Medium([UIScreen mainScreen].bounds.size.width/375*10);
    [self.climateRank_BackView addSubview:self.climateRank_maxTipsL];
    [self.climateRank_maxTipsL makeConstraints:^(MASConstraintMaker make) {
    make.centerY.equalTo(self.climateRank_BackView);
    make.right.mas_equalTo(self.climateRank_BackView.mas_right).offset(-[UIScreen mainScreen].bounds.size.width/375
    8);
    }];

    _currentPositionBut = [UIButton buttonWithType:UIButtonTypeCustom];
    [_currentPositionBut setBackgroundImage:[UIImage imageNamed:@"raderMap_currentLocation_icon"] forState:UIControlStateNormal];
    _currentPositionBut.adjustsImageWhenHighlighted = NO; // 点击时图片 不变灰色
    [self.currentPositionBut addTarget:self action:@selector(click_backCurrentPositionAction) forControlEvents:UIControlEventTouchUpInside];
    self.currentPositionBut.layer.masksToBounds = YES;
    self.currentPositionBut.layer.cornerRadius = [UIScreen mainScreen].bounds.size.width/37544/2;
    [self.view addSubview:self.currentPositionBut];
    [self.currentPositionBut makeConstraints:^(MASConstraintMaker make) {
    make.bottom.mas_equalTo(self.view.mas_bottom).offset(-(k_Height_TabBar + [UIScreen mainScreen].bounds.size.width/375
    19));
    make.right.mas_equalTo(self.view.mas_right).offset(-[UIScreen mainScreen].bounds.size.width/375
    12);
    make.width.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*44);
    }];

/** 播放/暂停:气候变化,(可以 手动滑动 刻度) */
_progress_BackView = [[UIView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/375*15, [UIScreen mainScreen].bounds.size.height - k_Height_TabBar - [UIScreen mainScreen].bounds.size.width/375*(19+44), [UIScreen mainScreen].bounds.size.width/375*290, [UIScreen mainScreen].bounds.size.width/375*44)];
_progress_BackView.backgroundColor = RGBA(248, 246, 242, 1);
self.progress_BackView.layer.cornerRadius = [UIScreen mainScreen].bounds.size.width/375*44/2;
self.progress_BackView.layer.shadowColor = RGBA(0, 0, 0, 0.12).CGColor;
self.progress_BackView.layer.shadowOffset = CGSizeMake(0, 0);
self.progress_BackView.layer.shadowRadius = [UIScreen mainScreen].bounds.size.width/375*4;
self.progress_BackView.layer.shadowOpacity = 1;
[self.view addSubview:self.progress_BackView];



/** 时间刻度的父view ,宽度:(290 - 40 -25) = 225*/
_progress_lineBackView = [[UIView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/375*40, 0, [UIScreen mainScreen].bounds.size.width/375*(225), [UIScreen mainScreen].bounds.size.width/375*44)];
self.progress_lineBackView.backgroundColor = UIColor.clearColor;//RGBA(212, 229, 225, 1);
[self.progress_BackView addSubview:self.progress_lineBackView];

_progress_beginTimeL = [[UILabel alloc] init];
_progress_beginTimeL.text = @" ";
_progress_beginTimeL.textColor = RGBA(153, 153, 153, 1);
_progress_beginTimeL.textAlignment = NSTextAlignmentLeft;
_progress_beginTimeL.font = FontSourceHanSerifCN_Medium([UIScreen mainScreen].bounds.size.width/375*12);
[self.progress_BackView addSubview:self.progress_beginTimeL];
[self.progress_beginTimeL makeConstraints:^(MASConstraintMaker *make) {        make.centerY.mas_equalTo(self.progress_BackView.mas_centerY).offset([UIScreen mainScreen].bounds.size.width/375*11);      make.left.mas_equalTo(self.progress_BackView.mas_left).offset([UIScreen mainScreen].bounds.size.width/375*40);
}];

_progress_endTimeL = [[UILabel alloc] init];
_progress_endTimeL.text = @" ";
_progress_endTimeL.textColor = RGBA(153, 153, 153, 1);
_progress_endTimeL.textAlignment = NSTextAlignmentRight;
_progress_endTimeL.font = FontSourceHanSerifCN_Medium([UIScreen mainScreen].bounds.size.width/375*12);
[self.progress_BackView addSubview:self.progress_endTimeL];
[self.progress_endTimeL makeConstraints:^(MASConstraintMaker *make) {     make.centerY.mas_equalTo(self.progress_BackView.mas_centerY).offset([UIScreen mainScreen].bounds.size.width/375*11);

make.right.mas_equalTo(self.progress_BackView.mas_right).offset(-[UIScreen mainScreen].bounds.size.width/375*25);
}];

_progress_currentLineView = [[UIView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/375*(40-1), 0, [UIScreen mainScreen].bounds.size.width/375*2, [UIScreen mainScreen].bounds.size.width/375*22)];
self.progress_currentLineView.backgroundColor = RGBA(193, 162, 122, 1);
[self.progress_BackView addSubview:self.progress_currentLineView];

// Touch触摸 view视图
_progress_view = [[UIView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/375*0, 0, [UIScreen mainScreen].bounds.size.width/375*290, [UIScreen mainScreen].bounds.size.width/375*44)];
self.progress_view.userInteractionEnabled = YES;
self.progress_view.backgroundColor = RGBA(88, 255, 88, 0);
[self.progress_BackView addSubview:self.progress_view];

// 开关:播放、暂停
_progress_playBut = [UIButton buttonWithType:UIButtonTypeCustom];
[_progress_playBut setBackgroundImage:[UIImage imageNamed:@"raderMap_playChange_icon"] forState:UIControlStateNormal];
[_progress_playBut setBackgroundImage:[UIImage imageNamed:@"raderMap_pauseChange_icon"] forState:UIControlStateSelected];
_progress_playBut.adjustsImageWhenHighlighted = NO; // 点击时图片 不变灰色
[self.progress_BackView addSubview:self.progress_playBut];
[self.progress_playBut makeConstraints:^(MASConstraintMaker *make) {
    make.centerY.equalTo(self.progress_BackView);
    make.left.mas_equalTo(self.progress_BackView.mas_left).offset([UIScreen mainScreen].bounds.size.width/375*10);
    make.width.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*24);
}];
[self.progress_playBut addTarget:self action:@selector(click_playClimateChangeAction) forControlEvents:UIControlEventTouchUpInside];


_progress_tipsL = [[UILabel alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/375*(15+40 - 30), [UIScreen mainScreen].bounds.size.height - k_Height_TabBar - [UIScreen mainScreen].bounds.size.width/375*(19+44+22), [UIScreen mainScreen].bounds.size.width/375*60, [UIScreen mainScreen].bounds.size.width/375*22)];
_progress_tipsL.backgroundColor = RGBA(193, 162, 122, 1);
_progress_tipsL.textColor = UIColor.whiteColor;
_progress_tipsL.textAlignment = NSTextAlignmentCenter;
_progress_tipsL.font = FontSourceHanSerifCN_Medium([UIScreen mainScreen].bounds.size.width/375*9);
_progress_tipsL.layer.masksToBounds = YES;
_progress_tipsL.layer.cornerRadius = [UIScreen mainScreen].bounds.size.width/375*22/2;
[self.view addSubview:self.progress_tipsL];


self.climateRank_minTipsL.text = @"-40°";
self.climateRank_maxTipsL.text = @"40°";
self.progress_BackView.hidden = YES;
self.progress_tipsL.hidden = YES;

}

@end

相关文章

网友评论

      本文标题:iOS ~ 高德地图:1、示例:

      本文链接:https://www.haomeiwen.com/subject/vwilnrtx.html