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

1.修改iOS Apex Mobil地图缩放。

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

+ 64 - 1
Apex Mobile/Apex Mobile/DetailPageViewController.m

@@ -115,7 +115,7 @@
 
 @end
 
-@interface DetailPageViewController () <QLPreviewControllerDataSource,QLPreviewControllerDelegate,DetailKVCellTapDelegate,AMCommHeadCellDelegate,AMCommContentCellDelegate,AMCommEditCellDelegate,CNContactPickerDelegate>
+@interface DetailPageViewController () <QLPreviewControllerDataSource,QLPreviewControllerDelegate,DetailKVCellTapDelegate,AMCommHeadCellDelegate,AMCommContentCellDelegate,AMCommEditCellDelegate,CNContactPickerDelegate,AMShipMapDelegate>
 
 @property (nonatomic,strong) MyQLPreviewController *quickLook;
 @property (nonatomic,copy) NSString *documentPath;
@@ -256,6 +256,8 @@
         self.shipMap.showPor = YES;
         self.shipMap.showOrigin = YES;
         self.shipMap.showDestination = YES;
+        
+        self.shipMap.delegate = self;
     }
     
 }
@@ -1911,4 +1913,65 @@
     self.content.segments = arr;
 }
 
+#pragma mark - ShipMap Delegate
+
+- (void)shipMap:(AMShipMap *)shipMap tryToZoomIn:(BOOL)zoomIn {
+    
+    if (zoomIn) {
+        
+        NSArray *constraints = self.view.constraints;
+        NSLayoutConstraint *h_ratio_constraint = nil;
+        
+        for (NSLayoutConstraint *constraint in constraints) {
+            if (constraint.identifier && [constraint.identifier isEqualToString:@"ratio_constraint"]) {
+                h_ratio_constraint = constraint;
+            }
+        }
+        
+        if (h_ratio_constraint) {
+            [self.view removeConstraint:h_ratio_constraint];
+        }
+        
+        NSLayoutConstraint *table_h_constraint = [NSLayoutConstraint constraintWithItem:self.table
+                                                                              attribute:NSLayoutAttributeHeight
+                                                                              relatedBy:NSLayoutRelationEqual
+                                                                                 toItem:nil
+                                                                              attribute:NSLayoutAttributeNotAnAttribute
+                                                                             multiplier:0
+                                                                               constant:0];
+        table_h_constraint.identifier = @"table_height";
+        [self.view addConstraint:table_h_constraint];
+        
+    } else {
+        
+        NSArray *constraints = self.view.constraints;
+        NSLayoutConstraint *h_constraint = nil;
+        
+        for (NSLayoutConstraint *constraint in constraints) {
+            if (constraint.identifier && [constraint.identifier isEqualToString:@"table_height"]) {
+                h_constraint = constraint;
+            }
+        }
+        
+        if (h_constraint) {
+            [self.view removeConstraint:h_constraint];
+        }
+        
+        float h_ratio = 0.5;
+        NSLayoutConstraint *h_ratio_constraint = [NSLayoutConstraint constraintWithItem:shipMap
+                                                                              attribute:NSLayoutAttributeHeight
+                                                                              relatedBy:NSLayoutRelationEqual
+                                                                                 toItem:self.table
+                                                                              attribute:NSLayoutAttributeHeight
+                                                                             multiplier:h_ratio
+                                                                               constant:0];
+        h_ratio_constraint.identifier = @"ratio_constraint";
+        
+        [self.view addConstraint:h_ratio_constraint];
+    }
+    
+    
+    [self.view layoutIfNeeded];
+}
+
 @end

+ 64 - 1
Apex Mobile/Apex Mobile/HomeViewController.m

@@ -25,7 +25,7 @@ typedef enum {
     HomeModeKPI = 1
 } HomeMode;
 
-@interface HomeViewController () <UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,KPIDelegate,ShipCellDelegate>
+@interface HomeViewController () <UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,KPIDelegate,ShipCellDelegate,AMShipMapDelegate>
 
 @property (strong, nonatomic) IBOutlet UISegmentedControl *segmentControl;
 
@@ -142,6 +142,8 @@ typedef enum {
     self.mapView.showPor = YES;
     self.mapView.showOrigin = YES;
     self.mapView.showDestination = YES;
+    
+    self.mapView.delegate = self;
 }
 
 - (void)configureNavigationBar {
@@ -850,4 +852,65 @@ typedef enum {
     [self setSelectedIndexPath:indexPath shipCell:cell];
 }
 
+#pragma mark - ShipMap Delegate
+
+- (void)shipMap:(AMShipMap *)shipMap tryToZoomIn:(BOOL)zoomIn {
+
+    if (zoomIn) {
+        
+        NSArray *constraints = self.ShipContainer.constraints;
+        NSLayoutConstraint *h_ratio_constraint = nil;
+        
+        for (NSLayoutConstraint *constraint in constraints) {
+            if (constraint.identifier && [constraint.identifier isEqualToString:@"map_height_ratio"]) {
+                h_ratio_constraint = constraint;
+            }
+        }
+        
+        if (h_ratio_constraint) {
+            [self.ShipContainer removeConstraint:h_ratio_constraint];
+        }
+        
+        NSLayoutConstraint *table_h_constraint = [NSLayoutConstraint constraintWithItem:self.shipTableView
+                                                                              attribute:NSLayoutAttributeHeight
+                                                                              relatedBy:NSLayoutRelationEqual
+                                                                                 toItem:nil
+                                                                              attribute:NSLayoutAttributeNotAnAttribute
+                                                                             multiplier:0
+                                                                               constant:120.0f];
+        table_h_constraint.identifier = @"ship_table_height";
+        [self.ShipContainer addConstraint:table_h_constraint];
+        
+    } else {
+
+        NSArray *constraints = self.ShipContainer.constraints;
+        NSLayoutConstraint *h_constraint = nil;
+        
+        for (NSLayoutConstraint *constraint in constraints) {
+            if (constraint.identifier && [constraint.identifier isEqualToString:@"ship_table_height"]) {
+                h_constraint = constraint;
+            }
+        }
+        
+        if (h_constraint) {
+            [self.ShipContainer removeConstraint:h_constraint];
+        }
+        
+        float h_ratio = 0.5;
+        NSLayoutConstraint *h_ratio_constraint = [NSLayoutConstraint constraintWithItem:shipMap
+                                                                              attribute:NSLayoutAttributeHeight
+                                                                              relatedBy:NSLayoutRelationEqual
+                                                                                 toItem:self.shipTableView
+                                                                              attribute:NSLayoutAttributeHeight
+                                                                             multiplier:h_ratio
+                                                                               constant:0];
+        h_ratio_constraint.identifier = @"map_height_ratio";
+        
+        [self.ShipContainer addConstraint:h_ratio_constraint];
+    }
+    
+    
+    [self.ShipContainer layoutIfNeeded];
+}
+
 @end

+ 1 - 1
Apex Mobile/Apex Mobile/Main.storyboard

@@ -388,7 +388,7 @@
                                 </subviews>
                                 <color key="backgroundColor" red="0.90612856220000004" green="0.90612856220000004" blue="0.90612856220000004" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                                 <constraints>
-                                    <constraint firstItem="3XI-3N-fFl" firstAttribute="height" secondItem="iIl-j9-7oa" secondAttribute="height" multiplier="1:2" id="0GT-rR-dp3"/>
+                                    <constraint firstItem="3XI-3N-fFl" firstAttribute="height" secondItem="iIl-j9-7oa" secondAttribute="height" multiplier="1:2" identifier="map_height_ratio" id="0GT-rR-dp3"/>
                                     <constraint firstItem="3XI-3N-fFl" firstAttribute="leading" secondItem="TYb-wc-Nwg" secondAttribute="leading" constant="5" id="1iS-rP-Kd6"/>
                                     <constraint firstItem="3XI-3N-fFl" firstAttribute="top" secondItem="TYb-wc-Nwg" secondAttribute="top" constant="2" id="386-pN-3RJ"/>
                                     <constraint firstItem="iIl-j9-7oa" firstAttribute="width" secondItem="TYb-wc-Nwg" secondAttribute="width" id="3bU-Ll-nT0"/>

+ 23 - 0
Apex Mobile/Apex Mobile/NewImages.xcassets/resize_max.imageset/Contents.json

@@ -0,0 +1,23 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "filename" : "resize_max.png",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "resize_max@2x.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "resize_max@3x.png",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

BIN
Apex Mobile/Apex Mobile/NewImages.xcassets/resize_max.imageset/resize_max.png


BIN
Apex Mobile/Apex Mobile/NewImages.xcassets/resize_max.imageset/resize_max@2x.png


BIN
Apex Mobile/Apex Mobile/NewImages.xcassets/resize_max.imageset/resize_max@3x.png


+ 23 - 0
Apex Mobile/Apex Mobile/NewImages.xcassets/resize_min.imageset/Contents.json

@@ -0,0 +1,23 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "filename" : "resize_min.png",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "resize_min@2x.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "resize_min@3x.png",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

BIN
Apex Mobile/Apex Mobile/NewImages.xcassets/resize_min.imageset/resize_min.png


BIN
Apex Mobile/Apex Mobile/NewImages.xcassets/resize_min.imageset/resize_min@2x.png


BIN
Apex Mobile/Apex Mobile/NewImages.xcassets/resize_min.imageset/resize_min@3x.png


+ 12 - 0
Apex Mobile/Apex Mobile/ShipMap/AMShipMap.h

@@ -8,6 +8,15 @@
 
 #import <UIKit/UIKit.h>
 
+@class AMShipMap;
+@protocol AMShipMapDelegate <NSObject>
+
+@optional
+
+- (void)shipMap:(AMShipMap *)shipMap tryToZoomIn:(BOOL)zoomIn;
+
+@end
+
 @interface AMShipMap : UIView
 
 @property (nonatomic,assign) BOOL showPol;///< 默认YES
@@ -17,6 +26,9 @@
 @property (nonatomic,assign) BOOL showOrigin;///< 默认NO
 @property (nonatomic,assign) BOOL showDestination;///< 默认NO
 @property (nonatomic,assign) BOOL showCurrent;///< 默认YES
+@property (nonatomic,assign) BOOL showZoomControl;///<默认YES
+
+@property (nonatomic,weak) id<AMShipMapDelegate> delegate;
 
 - (void)showShipAnnotaion:(NSDictionary *)annotation;
 

+ 46 - 0
Apex Mobile/Apex Mobile/ShipMap/AMShipMap.m

@@ -33,6 +33,7 @@ typedef enum {
 @interface AMShipMap () <MKMapViewDelegate>
 
 @property (nonatomic,strong) AMMapView *mapView;
+@property (nonatomic,strong) UIButton *resizeBtn;
 
 @end
 
@@ -203,15 +204,60 @@ typedef enum {
 //    return nil;
 }
 
+#pragma mark - Action
+
+- (void)resizeButtonClick:(UIButton *)sender {
+    sender.selected = !sender.selected;
+    
+    if (self.delegate && [self.delegate respondsToSelector:@selector(shipMap:tryToZoomIn:)]) {
+        [self.delegate shipMap:self tryToZoomIn:sender.selected];
+    }
+}
+
+#pragma mark - Setter
+
+- (void)setShowZoomControl:(BOOL)showZoomControl {
+    _showZoomControl = showZoomControl;
+    self.resizeBtn.hidden = !_showZoomControl;
+}
+
 #pragma mark - Life
 
 - (void)setup {
     
     [self setupMap];
     
+    self.resizeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
+    [self.resizeBtn setImage:[UIImage imageNamed:@"resize_max"] forState:UIControlStateNormal];
+    [self.resizeBtn setImage:[UIImage imageNamed:@"resize_min"] forState:UIControlStateSelected];
+    [self.resizeBtn addTarget:self action:@selector(resizeButtonClick:) forControlEvents:UIControlEventTouchUpInside];
+    self.resizeBtn.translatesAutoresizingMaskIntoConstraints = NO;
+    [self addSubview:self.resizeBtn];
+    
+    NSLayoutConstraint *top = [NSLayoutConstraint constraintWithItem:self.resizeBtn
+                                                           attribute:NSLayoutAttributeTop
+                                                           relatedBy:NSLayoutRelationEqual
+                                                              toItem:self
+                                                           attribute:NSLayoutAttributeTop
+                                                          multiplier:1.0
+                                                            constant:10];
+
+    NSLayoutConstraint *right = [NSLayoutConstraint constraintWithItem:self.resizeBtn
+                                                             attribute:NSLayoutAttributeRight
+                                                             relatedBy:NSLayoutRelationEqual
+                                                                toItem:self
+                                                             attribute:NSLayoutAttributeRight
+                                                            multiplier:1.0
+                                                              constant:-10];
+    
+    [self addConstraints:@[top,right]];
+    
+    [self layoutIfNeeded];
+    
     self.showPol = YES;
     self.showPod = YES;
     self.showCurrent = YES;
+    self.showZoomControl = YES;
 }
 
 - (void)setupMap {