MapKit缩放和CAKeyframeAnimation类使用!

- (void)setMapLocation:(CLLocationCoordinate2D)coordinate distance:(double)distance animated:(BOOL)animated{
    //[self saveLocationLatitude:coordinate.latitude Longitude:coordinate.longitude ];
    MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(coordinate, distance, distance);
    MKCoordinateRegion adjustedRegion = [self.mapView regionThatFits:viewRegion];
    [self.mapView setRegion:adjustedRegion animated:animated];
}


如上可以缩放地图


CAKeyframeAnimation类使用

-(CAAnimation*)animation {
    
    
    CAKeyframeAnimation* animation;
    animation = [CAKeyframeAnimation animation];
    animation.path = path;
    CGPathRelease(path);
    animation.duration = 5;
    animation.repeatCount = 10000;
     animation.calculationMode = @"cubic";
    animation.calculationMode=kCAAnimationCubicPaced;
        return animation;
}

-(CAAnimation*)fadeInOutAnimation{
    CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    animation.duration = 5;
    animation.repeatCount =10000;
    animation.toValue = [NSNumber numberWithFloat:.4];
    animation.autoreverses = YES;
    return animation;
}

-(void)startMoving{
    
    
   // [self.layer addAnimation:[self animation] forKey:@"position"];//圆周运动
    [imgView.layer addAnimation:[self animation] forKey:@"position"];
    [self.layer addAnimation:[self fadeInOutAnimation] forKey:@"opacity"];//阴影转动效果
    
   
    self.layer.needsDisplayOnBoundsChange = YES;
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    self.layer.position = CGPointMake(100, 100);
    self.layer.opacity = .4;
}

- (void) dealloc
{
    CGPathRelease(path);

    [super dealloc];
}


-(void)initPath{
    
    
    path = CGPathCreateMutable();

    CAShapeLayer *line =  [CAShapeLayer layer];
    
    
    line.lineWidth = 2.0f ;
    line.strokeColor = [UIColor orangeColor].CGColor;
    line.fillColor = [UIColor clearColor].CGColor;
    
    CGPathAddEllipseInRect(path, NULL, CGRectMake(100, 200, 200, 100));//椭圆路径,关键步骤。

    line.path = path;
    CGPathRelease(path);
    [self.layer addSublayer:line];
}

- (id)initWithFrame:(CGRect)aRect{
    self = [super initWithFrame:aRect];
    if(self != nil){
        [self initPath];

        imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 165, 82)];
        imgView.image = [UIImage imageNamed:@"weather_sun.png.png"];
        imgView.opaque = NO;
         [self addSubview:imgView];
        [self startMoving];
        [imgView release];
        return  self;
        
}

 


你可能感兴趣的:(MapKit缩放和CAKeyframeAnimation类使用!)