Kaynağa Gözat

2.修改iOS Apex Mobile Recent图标点击选中状态。

Pen Li 8 yıl önce
ebeveyn
işleme
748038049b

+ 21 - 2
Apex Mobile/Apex Mobile/HomeViewController.m

@@ -54,6 +54,7 @@ typedef enum {
 @property (nonatomic,assign) BOOL kpiRefresh;
 
 @property (nonatomic,strong) IBOutlet MKMapView *mapView;
+@property (nonatomic,strong) NSIndexPath *iconSelectedIndexPath;
 
 @end
 
@@ -327,6 +328,7 @@ typedef enum {
                 
                 [self.shipArray removeAllObjects];
                 [self.shipArray addObjectsFromArray:[json objectForKey:@"container_list"]];
+                self.iconSelectedIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
                 [self.shipTableView reloadData];
                 
             } else {
@@ -523,6 +525,10 @@ typedef enum {
         
         [[[[[[[[cell setTitle:title] setDescription:desc] setDetail:detail] setPort:port] setTime:date] setIcon:icon] setTransportStage:stage] setDelegate:self];
         
+        if (self.iconSelectedIndexPath && self.iconSelectedIndexPath.section == indexPath.section) {
+            [self setSelectedIndexPath:self.iconSelectedIndexPath shipCell:cell];
+        }
+        
         return cell;
     } else {
         
@@ -800,7 +806,20 @@ typedef enum {
     return returnDic;
 }
 
-- (void)setSelectedIndexPath:(NSIndexPath *)indexPath {
+- (void)setSelectedIndexPath:(NSIndexPath *)indexPath shipCell:(ShipingStatusCell *)shipCell {
+    if (indexPath == nil) {
+        return;
+    }
+    if (self.iconSelectedIndexPath) {
+        ShipingStatusCell *cell = [self.shipTableView cellForRowAtIndexPath:self.iconSelectedIndexPath];
+        [cell setIconSelect:NO];
+    }
+    self.iconSelectedIndexPath = indexPath;
+    ShipingStatusCell *cell = [self.shipTableView cellForRowAtIndexPath:indexPath];
+    if (cell == nil) { // 滑动过程中,dequeue方法中设置选中
+        cell = shipCell;
+    }
+    [cell setIconSelect:YES];
     
     [self.mapView removeAnnotations:self.mapView.annotations];
     
@@ -878,7 +897,7 @@ typedef enum {
 
 - (void)shipCellDidTapIcon:(ShipingStatusCell *)cell {
     NSIndexPath *indexPath = [self.shipTableView indexPathForCell:cell];
-    [self setSelectedIndexPath:indexPath];
+    [self setSelectedIndexPath:indexPath shipCell:cell];
 }
 
 @end

+ 1 - 0
Apex Mobile/Apex Mobile/ShipingStatusCell.h

@@ -28,5 +28,6 @@
 - (instancetype)setDetail:(NSString *)detail;
 - (instancetype)setIcon:(NSString *)icon;
 - (instancetype)setTransportStage:(NSInteger)stage;
+- (instancetype)setIconSelect:(BOOL)select;
 
 @end

+ 29 - 1
Apex Mobile/Apex Mobile/ShipingStatusCell.m

@@ -168,10 +168,38 @@
     return self;
 }
 
+- (instancetype)setIconSelect:(BOOL)select {
+    if (select) {
+        
+        CGFloat w = CGRectGetWidth(self.iconView.bounds);
+        CGFloat h = CGRectGetHeight(self.iconView.bounds);
+        CGFloat r = MIN(w, h) * 0.5;
+        UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.iconView.bounds cornerRadius:r];
+        CAShapeLayer *mask = [CAShapeLayer layer];
+        mask.lineWidth = 1.0f;
+        mask.strokeColor = [UIColor redColor].CGColor;
+        mask.fillColor = [UIColor clearColor].CGColor;
+        mask.path = path.CGPath;
+//        self.iconView.layer.mask = mask;
+        mask.name = @"am_mask";
+        [self.iconView.layer addSublayer:mask];
+        
+    } else {
+//        self.iconView.layer.mask = nil;
+        NSMutableArray *mArr = [self.iconView.layer.sublayers mutableCopy];
+        for (CALayer *layer in mArr) {
+            if ([layer isKindOfClass:[CAShapeLayer class]] && [layer.name isEqualToString:@"am_mask"]) {
+                [layer removeFromSuperlayer];
+            }
+        }
+    }
+    return self;
+}
+
 - (void)prepareForReuse {
     [super prepareForReuse];
     
-    [[[[[[[self setTitle:nil] setPort:nil] setTime:nil] setDescription:nil] setDetail:nil] setIcon:nil] setDelegate:nil];
+    [[[[[[[[self setTitle:nil] setPort:nil] setTime:nil] setDescription:nil] setDetail:nil] setIcon:nil] setIconSelect:NO] setDelegate:nil];
 }
 
 #pragma mark - Action