2011-09-21 2 views
0

여기 내 질문입니다. 이미지를 움직이게하고 싶습니다. 이미지를 다른 이미지로 돌리고 싶습니다.하지만 어떻게 할 지 모르겠습니다. 나는 그것이 회전하는 것을 원한다. (회전이 아니라 회전하는 것이 원을 돌고있는 것처럼). 어떻게하면 좋을까? 다음mak a uiimageView 다른 이미지를 뒤집기

-(void){ 
CALayer *orbit1 = [CALayer layer]; 
orbit1.bounds = CGRectMake(0, 0, 200, 200); 
orbit1.position = centre.center; 
orbit1.cornerRadius = 100; 
orbit1.borderColor= [UIColor redColor].CGColor; 
orbit1.borderWidth = 1.5; 

planet1 = [CALayer layer]; 
planet1.bounds = CGRectMake(0, 0, 44.0, 20.0); 
planet1.position = CGPointMake(160, 25); 
planet1.contents = (id)([UIImage imageNamed:@"bouletest_05.png"].CGImage); 
[orbit1 addSublayer:planet1]; 

CABasicAnimation *anim1 = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; 
anim1.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; 
anim1.fromValue = [NSNumber numberWithFloat:0]; 
anim1.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)]; 
anim1.repeatCount = HUGE_VALF; 
anim1.duration = 10.0; 
[orbit1 addAnimation:anim1 forKey:@"transform"]; 

[self.view.layer addSublayer:orbit1]; 

}

과 : 마지막 줄에

-(void)creation{ 

imageView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"abouffer_03.png"]]; 
[[self view] addSubview:imageView2]; 
imageView2.center=planet1.center; 
} 

보기 : 여기


내 코드입니다 imageView2.center = planet1.center; 문제가 여기에 있습니다

+2

[Quartz 2D Programming guide] (http://developer.apple.com/library/mac/documentation/graphicsimaging/conceptual/drawingwithquartz2d/dq_affine/dq_affine.html#//apple_ref/doc/uid/TP30001066-CH204)를 확인하십시오. -SW1). 그것은 아주 잘 설명합니다. – ender

답변

3

이 게시물을 확인하십시오 : http://nachbaur.com/blog/core-animation-part-4. 여기서 임의의 UIBezierPath를 따라 뷰를 애니메이션화하는 방법의 예를 찾을 수 있습니다.

const CGFloat radius = 100.0f; 
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(center.x-radius, center.y-radius, 2*radius, 2*radius)]; 

을 이동하려는 이미지보기로 해당 경로로 CAKeyFrameAnimation을 추가

그래서 경우에 당신은 당신의 '앵커'이미지 주위에 원 경로를 만들어야합니다.

+0

죄송 합니다만 CAKeyFrameAnimation을 이미지보기에 추가하려면 약간의 문제가 있습니다. 어떻게해야 할 지 모르겠다. –

+0

@Valentin, 연결된 블로그 게시물을 따르십시오. - 애니메이션을 추가하는 방법을 보여줍니다. . 거기에 묘사 된 것에 특별한 문제가 있습니까? – Vladimir

+0

예 bezierPAth 등을 사용하지 않습니다 ... xcode에 쓸 때 - (무효) {then your code} 아무 것도 작동하지 않습니다. –