Просмотр исходного кода

1.修改iOS Apex Ship Map当前位置点闪烁。

Pen Li 8 лет назад
Родитель
Сommit
f6c7075c04

+ 8 - 0
Apex Mobile/Apex Mobile/DetailPageViewController.m

@@ -204,11 +204,19 @@
     if ([action_type isEqualToString:@"Detail"]) { // 避免Tap与Tacking中Cell点击冲突
         [self startListenKeyboard];
     }
+    
+    if (self.shipMap) {
+        [self.shipMap shipMapWillAppear];
+    }
 }
 
 - (void)viewWillDisappear:(BOOL)animated {
     [super viewWillDisappear:animated];
     [self stopListenKeyboard];
+    
+    if (self.shipMap) {
+        [self.shipMap shipMapWillDisappear];
+    }
 }
 
 - (void)configureTableView {

+ 6 - 0
Apex Mobile/Apex Mobile/HomeViewController.m

@@ -107,6 +107,8 @@ typedef enum {
         if (self.shipArray.count == 0 || self.recentRefresh) {
             [self loadData];
         }
+        [self.mapView shipMapWillAppear];
+        
     } else if (self.mode == HomeModeKPI) {
         if (self.KPIArray.count == 0 || self.kpiRefresh) {
             [self loadKPIData];
@@ -122,6 +124,7 @@ typedef enum {
     [super viewWillDisappear:animated];
     
     self.parentViewController.title = nil;
+    [self.mapView shipMapWillDisappear];
 }
 
 - (void)clearNavigationbar {
@@ -462,6 +465,7 @@ typedef enum {
             self.parentViewController.title = str;
         }
         
+        [self.mapView shipMapWillDisappear];
         
     } else {
         self.mode = HomeModeRecent;
@@ -471,6 +475,8 @@ typedef enum {
         if (self.shipArray.count == 0 || self.recentRefresh) {
             [self loadData];
         }
+        
+        [self.mapView shipMapWillAppear];
     }
     
     

+ 5 - 1
Apex Mobile/Apex Mobile/ShipMap/AMShipMap.h

@@ -12,9 +12,9 @@
 @protocol AMShipMapDelegate <NSObject>
 
 @optional
-
 - (void)shipMap:(AMShipMap *)shipMap tryToZoomIn:(BOOL)zoomIn;
 
+
 @end
 
 @interface AMShipMap : UIView
@@ -27,9 +27,13 @@
 @property (nonatomic,assign) BOOL showDestination;///< 默认NO
 @property (nonatomic,assign) BOOL showCurrent;///< 默认YES
 @property (nonatomic,assign) BOOL showZoomControl;///<默认YES
+@property (nonatomic,assign) BOOL twinkleCurrent;//<默认YES
 
 @property (nonatomic,weak) id<AMShipMapDelegate> delegate;
 
 - (void)showShipAnnotaion:(NSDictionary *)annotation;
 
+- (void)shipMapWillAppear;///<视图显示的时候开启Current位置点闪烁Timer
+- (void)shipMapWillDisappear;///<视图消失的时候关闭Current位置点闪烁Timer
+
 @end

+ 76 - 1
Apex Mobile/Apex Mobile/ShipMap/AMShipMap.m

@@ -23,6 +23,7 @@ typedef enum {
 
 @property (nonatomic,assign) AMShipAnnotationPriority priority;
 @property (nonatomic,copy) NSString *imageName;
+@property (nonatomic,assign) BOOL isCurrent;
 
 @end
 
@@ -31,7 +32,11 @@ typedef enum {
 @end
 
 @interface AMShipMap () <MKMapViewDelegate>
-
+{
+    MKAnnotationView *_currentAnnotaion;
+    NSTimer *_twinkleTimer;
+    float _timerAngle;
+}
 @property (nonatomic,strong) AMMapView *mapView;
 @property (nonatomic,strong) UIButton *resizeBtn;
 
@@ -71,6 +76,10 @@ typedef enum {
         ann.priority = priority;
         ann.imageName = imgName;
         
+        if ([port isEqualToString:@"Current"]) {
+            ann.isCurrent = YES;
+        }
+        
         // 将大头针数据模型添加到MKMapView上管理
         [self.mapView addAnnotation:ann];
         
@@ -157,6 +166,7 @@ typedef enum {
         }
         if (current && self.showCurrent) {
             [self moveToLocation:current];
+            
         } else if (pol && self.showPol) {
             [self moveToLocation:pol];
         } else if (pod && self.showPod) {
@@ -165,6 +175,61 @@ typedef enum {
     }
 }
 
+#pragma mark - Twinkle Current
+
+- (void)startTwinkle {
+    if (_twinkleTimer) {
+        return;
+    }
+    __weak typeof(self) weakSelf = self;
+    dispatch_async(dispatch_get_global_queue(0, 0), ^{
+        if (weakSelf) {
+            __strong typeof(weakSelf) strongSelf = weakSelf;
+            strongSelf->_twinkleTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(twinkleTimerExecute:) userInfo:nil repeats:YES];
+            [[NSRunLoop currentRunLoop] addTimer:strongSelf->_twinkleTimer forMode:NSDefaultRunLoopMode];
+            [[NSRunLoop currentRunLoop] run];
+        }
+    });
+}
+
+- (void)twinkleTimerExecute:(NSTimer *)timer {
+    if (!_currentAnnotaion) {
+        return;
+    }
+    __weak typeof(self) weakSelf = self;
+    dispatch_async(dispatch_get_main_queue(), ^{
+        if (weakSelf) {
+            __strong typeof(weakSelf) strongSelf = weakSelf;
+            
+            strongSelf->_timerAngle += 0.1;
+            if (strongSelf->_timerAngle == 3.1) {
+                strongSelf->_timerAngle = 0;
+            }
+            float alpha = ABS(cos(strongSelf->_timerAngle));
+            strongSelf->_currentAnnotaion.alpha = alpha;
+        }
+    });
+}
+
+- (void)stopTwinkle {
+    if (_twinkleTimer) {
+        [_twinkleTimer invalidate];
+        _twinkleTimer = nil;
+    }
+}
+
+#pragma mark - Apear
+
+- (void)shipMapWillAppear {
+    if (self.twinkleCurrent) {
+        [self startTwinkle];
+    }
+}
+
+- (void)shipMapWillDisappear {
+    [self stopTwinkle];
+}
+
 #pragma mark - Map Delegate
 
 // 当地图上添加了标注以后要执行的回调方法
@@ -196,6 +261,10 @@ typedef enum {
             }
         }
         
+        if (shipAnnotation.isCurrent) {
+            _currentAnnotaion = pinView;
+        }
+        
         return pinView;
     } else {
         return nil;
@@ -223,6 +292,11 @@ typedef enum {
 
 #pragma mark - Life
 
+- (void)dealloc {
+    
+    [self stopTwinkle];
+}
+
 - (void)setup {
     
     [self setupMap];
@@ -258,6 +332,7 @@ typedef enum {
     self.showPod = YES;
     self.showCurrent = YES;
     self.showZoomControl = YES;
+    self.twinkleCurrent = YES;
 }
 
 - (void)setupMap {