Commit 4c5ea2b7 authored by lmj_521aiau@163.com's avatar lmj_521aiau@163.com

no message

parent e3d8716d
...@@ -47,16 +47,20 @@ ...@@ -47,16 +47,20 @@
[self logCollection]; [self logCollection];
// @available(iOS 13.0,*)表示iOS 13.0及以上的系统,后面的*表示所有平台
if (@available(iOS 13.0,*)) {
}else{
self.window = [[UIWindow alloc] init]; self.window = [[UIWindow alloc] init];
self.window.frame = [UIScreen mainScreen].bounds; self.window.frame = [UIScreen mainScreen].bounds;
self.window.backgroundColor = [UIColor whiteColor]; self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = [UIViewController new];
// self.window.rootViewController = [[GuideViewController alloc] init];
//guide setting
[ZJGuideConfig configWithWindow:self.window finishMainVC:[BaseTabBarViewController new]];
[self.window makeKeyAndVisible]; [self.window makeKeyAndVisible];
self.window.rootViewController = [[BaseViewController alloc] init];
// guide setting
[ZJGuideConfig configWithWindow:self.window finishMainVC:[BaseTabBarViewController new]];
}
return YES; return YES;
} }
......
...@@ -21,24 +21,30 @@ ...@@ -21,24 +21,30 @@
#import <MapKit/MapKit.h> #import <MapKit/MapKit.h>
#import "ZJCustomAnnotation.h" #import "ZJCustomAnnotation.h"
#define AnimationDuration 8
@interface ZJFriendTrackMapViewController () <MAMapViewDelegate, MKMapViewDelegate, CAAnimationDelegate>{ @interface ZJFriendTrackMapViewController () <MAMapViewDelegate, MKMapViewDelegate, CAAnimationDelegate>{
float* hues; float* hues;
float *velocity; float *velocity;
ZJCustomAnnotation * startAnnotation; ZJCustomAnnotation * endAnnotation;
UIView * container; BOOL mapPaddle;
} }
@property (nonatomic, strong) ZJUserTrackTimeView *trackTimeView; @property (nonatomic, strong) ZJUserTrackTimeView *trackTimeView;
@property (strong, nonatomic) NSDate *stratDate; @property (strong, nonatomic) NSDate *stratDate;
@property (strong, nonatomic) NSDate *endDate; @property (strong, nonatomic) NSDate *endDate;
@property (nonatomic, strong) MKMapView *mapView; @property (nonatomic, strong) ZJAlertView *alertView;
@property (nonatomic, strong) MKMapView *mapView;
@property (nonatomic, strong) UIView * container;
@property (nonatomic, strong) NSMutableArray<ZJLocationModel *> *locations; @property (nonatomic, strong) NSMutableArray<ZJLocationModel *> *locations;
///全轨迹overlay ///全轨迹overlay
@property (strong, nonatomic) MKPolyline *commonPolyline; @property (strong, nonatomic) MKPolyline *commonPolyline;
@property (nonatomic, strong) ZJAlertView *alertView; @property (nonatomic, strong) MAPointAnnotation * startAnnotation;
@property (nonatomic, strong) MKAnnotationView * startAnnotationView;
@property (nonatomic, strong) MKAnnotationView * endAnnotationView;
@property (nonatomic, strong) CAShapeLayer * shapeLayer; @property (nonatomic, strong) CAShapeLayer * shapeLayer;
...@@ -49,11 +55,6 @@ ...@@ -49,11 +55,6 @@
@property (nonatomic, strong) CALayer * gradientLayer; @property (nonatomic, strong) CALayer * gradientLayer;
@property (nonatomic, strong) NSMutableArray * gradientColors; @property (nonatomic, strong) NSMutableArray * gradientColors;
/**
大头针 - 移动的大头针视图
*/
@property (nonatomic, weak) MKAnnotationView * annotationView;
@end @end
@implementation ZJFriendTrackMapViewController @implementation ZJFriendTrackMapViewController
...@@ -138,7 +139,7 @@ ...@@ -138,7 +139,7 @@
///初始化地图 ///初始化地图
self.mapView = [[MKMapView alloc] initWithFrame:self.view.bounds]; self.mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码 ///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
_mapView.showsUserLocation = YES; _mapView.showsUserLocation = false;
_mapView.delegate = self; _mapView.delegate = self;
_mapView.showsScale = false; _mapView.showsScale = false;
_mapView.showsCompass = false; _mapView.showsCompass = false;
...@@ -175,12 +176,20 @@ ...@@ -175,12 +176,20 @@
weakSelf.stratDate = beginDate; weakSelf.stratDate = beginDate;
weakSelf.endDate = endDate; weakSelf.endDate = endDate;
}; };
mapPaddle = YES;
startAnnotation = [[ZJCustomAnnotation alloc] init];
[_mapView addAnnotation:startAnnotation];
} }
- (void) drawLineAction1{ - (void)drawLineAction1{
// _endAnnotationView = nil;
// _startAnnotationView = nil;
[self.mapView removeAnnotations:self.mapView.annotations];
_trackAnimation = YES;
endAnnotation = [[ZJCustomAnnotation alloc] init];
[_mapView addAnnotation:endAnnotation];
_smoothTrackCount = _locations.count; _smoothTrackCount = _locations.count;
_smoothTrackPoints = malloc(sizeof(CLLocationCoordinate2D)*_smoothTrackCount); _smoothTrackPoints = malloc(sizeof(CLLocationCoordinate2D)*_smoothTrackCount);
...@@ -197,19 +206,64 @@ ...@@ -197,19 +206,64 @@
_smoothTrackPoints[i] = coordinate; _smoothTrackPoints[i] = coordinate;
} }
} }
_trackAnimation = YES;
} }
- (void) drawLineAction { - (void)addAnimation{
_container = (UIView *)[self.mapView.subviews firstObject].subviews.lastObject;
CGPoint *points = [self pointsForCoordinates:_smoothTrackPoints count:_smoothTrackCount];
CGPathRef path = [self pathForPoints:points count:_smoothTrackCount];
[self initShapeLayerWithPath:path];
self.shapeLayer.frame = self.mapView.bounds;
CAAnimation *shapeLayerAnimation = [self constructShapeLayerAnimation];
shapeLayerAnimation.delegate = self;
shapeLayerAnimation.removedOnCompletion = NO;
shapeLayerAnimation.fillMode = kCAFillModeForwards;
[self.shapeLayer addAnimation:shapeLayerAnimation forKey:@"shape"];
[self.container.layer addSublayer:self.shapeLayer];
[self initGradientLayerWithPoints:points Count:_smoothTrackCount];
ZJLocationModel * model = self.locations[0];
[endAnnotation setCoordinate:CLLocationCoordinate2DMake(model.latitude, model.longitude)];
_endAnnotationView = [self.mapView viewForAnnotation:endAnnotation];
CAAnimation *annotationAnimation = [self constructAnnotationAnimationWithPath:path];
_endAnnotationView.image = [UIImage imageNamed:kLocalizedString(@"map_track_end_icon")];
[_endAnnotationView.layer addAnimation:annotationAnimation forKey:@"annotation"];
[_endAnnotationView.annotation setCoordinate:_smoothTrackPoints[_smoothTrackCount - 1]];
[self.trackTimeView.trackButton setSelected:true]; [self.trackTimeView.trackButton setSelected:true];
[self.trackTimeView.trackButton setEnabled:false]; [self.trackTimeView.trackButton setEnabled:false];
//移除 self.mapView.userInteractionEnabled = NO;
[self.mapView removeOverlay:self.commonPolyline]; [self performSelector:@selector(removeLayer) withObject:nil afterDelay:AnimationDuration + 0.33];
(void)(free(points)), points = NULL;
(void)(CGPathRelease(path)), path = NULL;
_trackAnimation = NO;
mapPaddle = NO;
}
- (void)removeLayer{
_mapView.userInteractionEnabled = YES;
[self.trackTimeView.trackButton setSelected:false];
[self.trackTimeView.trackButton setEnabled:true];
[self.gradientLayer removeFromSuperlayer];
[self.shapeLayer removeFromSuperlayer];
_startAnnotation = [[MAPointAnnotation alloc] init];
_startAnnotation.coordinate = CLLocationCoordinate2DMake(self.locations.firstObject.latitude, self.locations.firstObject.longitude);
_startAnnotation.title = @"start";
[self.mapView addAnnotation:(id<MKAnnotation>)_startAnnotation];
}
- (void) drawLineAction {
// MAPointAnnotation *pointAnnotation1 = [[MAPointAnnotation alloc] init]; [self.mapView removeOverlays:self.mapView.overlays];
// pointAnnotation1.coordinate = CLLocationCoordinate2DMake(self.locations.firstObject.latitude, self.locations.firstObject.longitude);
// pointAnnotation1.title = @"start";
// [self.mapView addAnnotation:(id<MKAnnotation>)pointAnnotation1];
//构造折线数据对象 //构造折线数据对象
CLLocationCoordinate2D commonPolylineCoords[self.locations.count]; CLLocationCoordinate2D commonPolylineCoords[self.locations.count];
...@@ -219,82 +273,30 @@ ...@@ -219,82 +273,30 @@
commonPolylineCoords[i].longitude = self.locations[i].longitude; commonPolylineCoords[i].longitude = self.locations[i].longitude;
} }
// MAPointAnnotation *pointAnnotation2 = [[MAPointAnnotation alloc] init];
// pointAnnotation2.coordinate = CLLocationCoordinate2DMake(self.locations.lastObject.latitude, self.locations.lastObject.longitude);
// pointAnnotation2.title = @"end";
// [self.mapView addAnnotation:(id<MKAnnotation>)pointAnnotation2];
//构造折线对象 //构造折线对象
MKPolyline *commonPolyline = [MKPolyline polylineWithCoordinates:commonPolylineCoords count:self.locations.count]; MKPolyline *commonPolyline = [MKPolyline polylineWithCoordinates:commonPolylineCoords count:self.locations.count];
self.commonPolyline = commonPolyline; self.commonPolyline = commonPolyline;
//在地图上添加折线对象 //在地图上添加折线对象
[self.mapView addOverlay: commonPolyline]; [self.mapView addOverlay: self.commonPolyline];
int count = sizeof(commonPolylineCoords) / sizeof(commonPolylineCoords[0]);
self.mapView.centerCoordinate = commonPolylineCoords[count/2];
double sum = 0;
NSMutableArray *arr = [NSMutableArray arrayWithCapacity:count];
for(int i = 0; i < count - 1; ++i) {
CLLocation *begin = [[CLLocation alloc] initWithLatitude:commonPolylineCoords[i].latitude longitude:commonPolylineCoords[i].longitude];
CLLocation *end = [[CLLocation alloc] initWithLatitude:commonPolylineCoords[i+1].latitude longitude:commonPolylineCoords[i+1].longitude];
CLLocationDistance distance = [end distanceFromLocation:begin];
[arr addObject:[NSNumber numberWithDouble:distance]];
sum += distance;
}
MKMapRect rect = MKMapRectMake(self.commonPolyline.boundingMapRect.origin.x, self.commonPolyline.boundingMapRect.origin.y, self.commonPolyline.boundingMapRect.size.width, self.commonPolyline.boundingMapRect.size.height); MKMapRect rect = MKMapRectMake(self.commonPolyline.boundingMapRect.origin.x, self.commonPolyline.boundingMapRect.origin.y, self.commonPolyline.boundingMapRect.size.width, self.commonPolyline.boundingMapRect.size.height);
[self.mapView setVisibleMapRect:rect edgePadding:UIEdgeInsetsMake(250, 50, 50, 50) animated:true]; [self.mapView setVisibleMapRect:rect edgePadding:UIEdgeInsetsMake(250, 50, 50, 50) animated:true];
if (!mapPaddle) {
[self addAnimation];
}
} }
#pragma mark - Map Delegate #pragma mark - Map Delegate
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{
mapPaddle = YES;
}
- (void)mapViewDidFinishRenderingMap:(MKMapView *)mapView fullyRendered:(BOOL)fullyRendered{ - (void)mapViewDidFinishRenderingMap:(MKMapView *)mapView fullyRendered:(BOOL)fullyRendered{
if (_trackAnimation) { if (_trackAnimation) {
[self addAnimation];
container = (UIView *)[mapView.subviews firstObject].subviews.lastObject;
CGPoint *points = [self pointsForCoordinates:_smoothTrackPoints count:_smoothTrackCount];
CGPathRef path = [self pathForPoints:points count:_smoothTrackCount];
[self initShapeLayerWithPath:path];
self.shapeLayer.frame = self.mapView.bounds;
CAAnimation *shapeLayerAnimation = [self constructShapeLayerAnimation];
shapeLayerAnimation.delegate = self;
shapeLayerAnimation.removedOnCompletion = NO;
shapeLayerAnimation.fillMode = kCAFillModeForwards;
[self.shapeLayer addAnimation:shapeLayerAnimation forKey:@"shape"];
[self.mapView.layer addSublayer:self.shapeLayer];
[self initGradientLayerWithPoints:points Count:_smoothTrackCount];
ZJLocationModel * model = self.locations[0];
[startAnnotation setCoordinate:CLLocationCoordinate2DMake(model.latitude, model.longitude)];
MKAnnotationView *annotationView = [self.mapView viewForAnnotation:startAnnotation];
CAAnimation *annotationAnimation = [self constructAnnotationAnimationWithPath:path];
annotationView.image = [UIImage imageNamed:@"map_track_start_icon"];
[annotationView.layer addAnimation:annotationAnimation forKey:@"annotation"];
[annotationView.annotation setCoordinate:_smoothTrackPoints[_smoothTrackCount - 1]];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// [self.gradientLayer removeFromSuperlayer];
// [self.shapeLayer removeFromSuperlayer];
// MAPointAnnotation *pointAnnotation2 = [[MAPointAnnotation alloc] init];
// pointAnnotation2.coordinate = CLLocationCoordinate2DMake(self.locations.lastObject.latitude, self.locations.lastObject.longitude);
// pointAnnotation2.title = @"end";
// [self.mapView addAnnotation:(id<MKAnnotation>)pointAnnotation2];
});
(void)(free(points)), points = NULL;
(void)(CGPathRelease(path)), path = NULL;
_trackAnimation = NO;
} }
} }
...@@ -323,6 +325,7 @@ ...@@ -323,6 +325,7 @@
if ([annotation.title isEqualToString:@"start"]) { if ([annotation.title isEqualToString:@"start"]) {
annotationView.enabled = NO; annotationView.enabled = NO;
annotationView.image = [UIImage imageNamed:kLocalizedString(@"map_track_start_icon")]; annotationView.image = [UIImage imageNamed:kLocalizedString(@"map_track_start_icon")];
_startAnnotationView = (MKAnnotationView *)annotationView;
} else if ([annotation.title isEqualToString:@"end"]) { } else if ([annotation.title isEqualToString:@"end"]) {
annotationView.enabled = NO; annotationView.enabled = NO;
annotationView.image = [UIImage imageNamed:kLocalizedString(@"map_track_end_icon")]; annotationView.image = [UIImage imageNamed:kLocalizedString(@"map_track_end_icon")];
...@@ -339,7 +342,7 @@ ...@@ -339,7 +342,7 @@
} }
annotationView.enabled = NO; annotationView.enabled = NO;
// annotationView.image = [UIImage imageNamed:@"userPosition"]; annotationView.image = [UIImage imageNamed:@"userPosition"];
return annotationView; return annotationView;
} }
...@@ -523,7 +526,7 @@ ...@@ -523,7 +526,7 @@
#pragma mark - 构建shapeLayer的basicAnimation #pragma mark - 构建shapeLayer的basicAnimation
- (CAAnimation *)constructShapeLayerAnimation{ - (CAAnimation *)constructShapeLayerAnimation{
CABasicAnimation *theStrokeAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; CABasicAnimation *theStrokeAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
theStrokeAnimation.duration = 3; theStrokeAnimation.duration = AnimationDuration;
theStrokeAnimation.fromValue = @0.f; theStrokeAnimation.fromValue = @0.f;
theStrokeAnimation.toValue = @1.f; theStrokeAnimation.toValue = @1.f;
theStrokeAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; theStrokeAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
...@@ -537,7 +540,7 @@ ...@@ -537,7 +540,7 @@
} }
CAKeyframeAnimation *keyFrameAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; CAKeyframeAnimation *keyFrameAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
keyFrameAnimation.duration = 3; keyFrameAnimation.duration = AnimationDuration;
keyFrameAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; keyFrameAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
keyFrameAnimation.path = path; keyFrameAnimation.path = path;
keyFrameAnimation.calculationMode = kCAAnimationPaced; keyFrameAnimation.calculationMode = kCAAnimationPaced;
...@@ -623,7 +626,7 @@ ...@@ -623,7 +626,7 @@
} }
} }
[self.gradientLayer setMask:self.shapeLayer]; [self.gradientLayer setMask:self.shapeLayer];
[self.mapView.layer addSublayer:self.gradientLayer]; [self.container.layer addSublayer:self.gradientLayer];
} }
#define V_MAX 4.5 #define V_MAX 4.5
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment