UIImageView 의 IBOutlet 하나 필요, (helicopterImageVew)
충돌을 확인할 UIImageView 의 IBOutlet 도 하나 필요(birdImageView)
경로를 따라 이동하는 Path 버튼과 프로펠러 회전을 시키는 Swing 버튼을 위한 두 개의 IBAction 필요
//초기화 부분..
{
...
UIImage *heliImage1 = [UIImage imageNamed:@"heli_1.png"];
UIImage *heliImage2 = [UIImage imageNamed:@"heli_2.png"];
UIImage *heliImage3 = [UIImage imageNamed:@"heli_3.png"];
UIImage *heliImage4 = [UIImage imageNamed:@"heli_4.png"];
UIImage *heliImage5 = [UIImage imageNamed:@"heli_5.png"];
UIImage *heliImage6 = [UIImage imageNamed:@"heli_6.png"];
NSArray *animationImageArray = [NSArray arrayWithObjects:heliImage1, heliImage2,
heliImage3, heliImage4, heliImage5, heliImage6, nil];
helicopterImageView.animationImages = animationImageArray;
helicopterImageView.animationDuration = 0.1;
- (IBAction)toggleFlay:(id)sender
{
if ([helicopterImageView isAnimating]){
[helicopterImageView stopAnimating];
} else {
[helicopterImageView startAnimating];
}
}
- (IBAction)moveThroughPath:(id)sender
{
birdImageView.hidden = NO;
//패쓰 만들기
CGMutablePathRef aniPath = CGPathCreateMutable();
CGPoint currCenter = helicopterImageView.center;
CGAffineTransform xform = CGAffineTransformIdentity;
CGPathMoveToPoint(aniPath, &xform, currCenter.x, currCenter.y);
CGPathAddCurveToPoint(aniPath, &xform, -200, currCenter.y, 520, 400, 160, 400);
//애니메이션 만들기
CAKeyframeAnimation *keyAni = [CAKeyframeAnimation animation];
keyAni.duration = 4.0;
keyAni.path = aniPath;
keyAni.rotationMode = kCAAnimationRotateAutoReverse;
//레이어에 애니메이션을 더한다
[NSTimer scheduledTimerWithTimeInterval:0.1
target:self
selector:@selector(collisionCheck:) userInfo:nil repeats:YES];
[helicopterImageView.layer addAnimation:keyAni forKey:@"position"];
}
- (void)collisionCheck:(NSTimer *)timer
{
CALayer *presentationLayer = helicopterImageView.layer.presentationLayer;
CGRect presentationRect = presentationLayer.frame;
CGRect birdRect = birdImageView.frame;
if (CGRectIntersectsRect(presentationRect, birdRect)){
NSLog(@"Collision");
birdImageView.hidden = YES;
[timer invalidate];
timer = nil;
}
}
'iOS > Skills' 카테고리의 다른 글
UITableView 당겨서 업데이트 (0) | 2011.06.14 |
---|---|
모달 뷰 사용(일종의 팝업 윈도우) (1) | 2010.11.23 |
UIAlertView without Buttons - Please Wait Dialog (0) | 2010.07.21 |
MBProgressHUD (0) | 2010.07.21 |
UIBarButtonSystemItem 추가된 아이템 (0) | 2010.07.21 |