#define RANDOM_INT(MIN,MAX) ( (MIN) + arc4random() % ((MAX+1)-(MIN)) )
//CGSize offSize = [UIScreen mainScreen].bounds.size;
-(void)airAutoAnimation{
/* 움직이기 위한 대상 레이어를 만듭니다. */
CALayer *layer1 = [CALayer layer];
layer1.bounds = CGRectMake(0, 0, 20, 20);
int x = RANDOM_INT(0, 320) ;
int y = RANDOM_INT(0, 480) ;
layer1.position = CGPointMake( x, y );
layer1.cornerRadius = 20;
layer1.backgroundColor = [UIColor redColor].CGColor;
// [layer1 setHidden:YES];
[self.view.layer addSublayer:layer1]; // 만든 레이어를 뷰 레이어에 올립니다.
/* 이동할 위치 지정 */
CGMutablePathRef path1 = CGPathCreateMutable();
CGPathMoveToPoint(path1,NULL,layer1.position.x, layer1.position.y);
CGPathAddLineToPoint(path1, NULL, layer1.position.x, layer1.position.y + 150);
CGPathAddLineToPoint(path1, NULL, layer1.position.x + 100, layer1.position.y + 100);
CGPathAddLineToPoint(path1, NULL, layer1.position.x, layer1.position.y + 0);
/* 이동 애니메이션 작성 */
CAKeyframeAnimation *moveAni1 = [CAKeyframeAnimation animationWithKeyPath:@"position"];
moveAni1.path = path1;
moveAni1.rotationMode = kCAAnimationRotateAuto;
moveAni1.duration = 5.0;
/* 스케일 애니메이션 작성 */
CABasicAnimation *scalAni1 = [CABasicAnimation animationWithKeyPath:@"transform"];
scalAni1.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
scalAni1.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)];
scalAni1.duration = 5.0;
/* 투명 애니메이션 작성 */
CABasicAnimation *opacityAni1 = [CABasicAnimation animationWithKeyPath:@"opacity"];
opacityAni1.fromValue = [NSNumber numberWithFloat:1.0];
opacityAni1.toValue = [NSNumber numberWithFloat:0.1];
opacityAni1.duration = 5.0;
/* 애니메이션 그룹 작성 */
CAAnimationGroup *group = [CAAnimationGroup animation];
group.animations = [NSArray arrayWithObjects:moveAni1, scalAni1, opacityAni1, nil];
group.duration = 5.0;
[layer1 addAnimation:group forKey:nil]; //레이어에 그룹애니메이션 적용
//[layer1 removeFromSuperlayer];
/*
timerCounter++;
if (timerCounter > 5) {
[timer invalidate];
timer = nil;
}*/
}
'Developer > IOS' 카테고리의 다른 글
int 와 string (0) | 2013.03.19 |
---|---|
xcode 배경 반복 .. (0) | 2013.03.19 |
동적 xib 파일 교체 (0) | 2013.03.19 |
IOS date 핸들링. (0) | 2013.03.18 |
Timer use (0) | 2013.03.04 |