2015-01-24 2 views
0

UIImageView에 애니메이션을 적용하려고합니다. 기록 된 다음 코드 필자 :UIView 애니메이션 블록 변경이 즉시 발생합니까?

- (void)JumpAnimGoingDown { 
NSLog(@"Started"); 
//Sets what happens in animation 
self.character.frame = CGRectMake(self.view.frame.size.width/WidthDivision, (self.character.center.y - (self.view.frame.size.height/18)) + self.view.frame.size.height, (self.view.frame.size.height * 4)/45, self.view.frame.size.height/9); 



[UIView animateWithDuration:5.0f 
         delay:0 
        options:UIViewAnimationOptionCurveLinear 

       animations:^{ 

        [self.view layoutIfNeeded]; 
       } 
       completion:^(BOOL finished) { 
        // This block will execute when the animations finish 

        NSLog(@"Ended"); 

        [self.view layoutIfNeeded]; 
       } 
]; 

}

을하지만 코드에서이 메서드를 호출 할 때 변경 사항이 즉시 일어난다 : http://gyazo.com/b34fd7fa84ea25ace5cd656b4068e6aa 를 이것은 또한 나는이에 넣어하려고했습니다 다른 코드로 발생 애니메이션 블록. 솔직히 나는 왜 이런 일이 일어나고 있는지 또는 어떤 문제를 해결할 수 있는지 잘 모릅니다. 내가이 차이를하지 이전 코드에서 나는 그것이 일했다 작성한으로 다음과 같이

[UIView animateWithDuration:5.0f 

[UIImageView animateWithDuration:5.0f 

에 내가없는 변화 시도 궁금 분들을 위해

이것이 문제라고 생각합니다. 감사합니다.

답변

0

애니메이션을 적용하려는 모든 변경 사항은 animations 블록 내에 있어야합니다.

- (void)JumpAnimGoingDown 
{ 
    NSLog(@"Started"); 

    [UIView animateWithDuration:5.0f 
          delay:0 
         options:UIViewAnimationOptionCurveLinear 

        animations:^{ 
         //Sets what happens in animation 
         self.character.frame = CGRectMake(self.view.frame.size.width/WidthDivision, (self.character.center.y - (self.view.frame.size.height/18)) + self.view.frame.size.height, (self.view.frame.size.height * 4)/45, self.view.frame.size.height/9); 
        } 
        completion:^(BOOL finished) { 
         // This block will execute when the animations finish 

         NSLog(@"Ended"); 

         [self.view layoutIfNeeded]; 
        } 
    ]; 
} 
관련 문제