-(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 = [CABasicAnimationanimationWithKeyPath:@"opacity"];
animation.duration = 5;
animation.repeatCount =10000;
animation.toValue = [NSNumbernumberWithFloat:.4];
animation.autoreverses = YES;
returnanimation;
}
-(void)startMoving{
// [self.layeraddAnimation:[self animation] forKey:@"position"];//圆周运动
[imgView.layer addAnimation:[self animation]forKey:@"position"];
[self.layeraddAnimation:[self fadeInOutAnimation]forKey:@"opacity"];//阴影转动效果
self.layer.needsDisplayOnBoundsChange =YES;
[UIViewsetAnimationCurve:UIViewAnimationCurveLinear];
self.layer.position = CGPointMake(100,100);
self.layer.opacity = .4;
}
- (void) dealloc
{
CGPathRelease(path);
[superdealloc];
}
-(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.layeraddSublayer: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 = [UIImageimageNamed:@"weather_sun.png.png"];
imgView.opaque = NO;
[self addSubview:imgView];
[self startMoving];
[imgView release];
}
returnself;
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。