2009-07-19 5 views
0

iPhone의 잠금 해제 메커니즘과 같은 슬라이더 막대 유형의 UI 컨트롤을 구현했습니다.애니메이션이 포함 된 UIImageView 이동하기

touchesEnded 메서드가 호출되면 슬라이더를 시작 위치로 되돌립니다. 대신, 나는 그것의 시작 위치로 돌아 가기 위해 움직이게하고 싶습니다.

코드는 이와 같아야하지만 작동하지 않습니다. 여기서 내가 뭘 잘못하고 있니? 뼈 달린 질문에 대한

CABasicAnimation *theAnimation; 
theAnimation = [CABasicAnimation animationWithKeyPath:@"position.x"]; 
theAnimation.fromValue = [NSNumber numberWithFloat:BEGINX]; 
theAnimation.toValue = [NSNumber numberWithFloat: 0.0]; 
theAnimation.duration = 0.5; 
[self.unlock addAnimation: theAnimation]; 

죄송합니다 :

Self.unlock가있는 UIImageView입니다!

답변

3

암시 적 애니메이션을 사용하면 훨씬 간단하게이 작업을 수행 할 수 있습니다. 현재이 같은 일을하는 가정 :

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
    ... 
    myView.frame = startingFrame; 
    ... 
} 

당신은 (예 : 자사의 프레임으로) 당신이보기에 변경 사항을 애니메이션을 암시 적 애니메이터를 사용할 수 있습니다

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
    ... 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:0.5]; 
    myView.frame = startingFrame; 
    [UIView commitAnimations]; 
    ... 
} 
+0

안녕하세요, 감사합니다 ... 나는 그것을 잘못하고 있다고 생각한다. 다음 코드를 시도하고 "UIImageView 응답하지 않을 수 있습니다"두 번 경고 : \t \t [self.unlock beginAnimations : nil context : nil]; \t \t [self.unlock setAnimationDuration : 0.5]; \t \t self.unlock.frame = CGRectMake (0, 0, 75, 37); \t \t [self.unlock commitAnimations]; –

+0

신경 쓰지 마세요, 귀하의 코드가 정확하게 작성된 것으로 보입니다. 매력처럼 작동합니다. 감사! –

관련 문제