2013-03-25 9 views
0

애니메이션을 시작해야하는 함수가 있습니다. 삼각형은 "drawrect"로 디자인되어 있으며 컨트롤러에 버튼이 있습니다.이 버튼을 누르면 "startTriangleAnimation"이 호출됩니다.애니메이션 메쏘드 호출 UIView 애니메이션

문제는 "startTriagnleAnimation"이 애니메이션을 추가하지 않는 것입니다. NSLOG를 인쇄하기 때문에 프로그램이이 메서드에 들어 있다고 확신합니다.

누구나 어떻게 해야할지 알고 있나요?

- (void)startTriangleAnimation 
{ 
    [self setNeedsDisplay]; 
    if (_leftFoot) { 
      NSLog(@"LEFT FOOT ANIMATION STARTING"); 
     [UIView animateWithDuration:15 
           delay:0 
          options: UIViewAnimationOptionCurveLinear 
         animations:^{ 
          self.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(-FIRST_ROTATION)); 
         } completion:^(BOOL finished) { 
          [UIView animateWithDuration:15 
                delay:0.5 
               options: UIViewAnimationOptionCurveLinear 
               animations:^{ 
                self.transform = CGAffineTransformRotate(self.transform, DEGREES_TO_RADIANS(-SECOND_ROTATION)); 
               } completion:^(BOOL finished) { 
                [UIView animateWithDuration:15 
                     delay:0.5 
                     options: UIViewAnimationOptionCurveLinear 
                    animations:^{ 
                     self.transform = CGAffineTransformRotate(self.transform, DEGREES_TO_RADIANS(-THIRD_ROTATION)); 
                    }completion:^(BOOL finished) { 
                     [UIView animateWithDuration:15 
                         animations:^{ 
                          self.transform = CGAffineTransformRotate(self.transform, DEGREES_TO_RADIANS(-FOURTH_ROTATION)); 
                         }]; 
                    }]; 
               }]; 
         }]; 



    } else { 
     NSLog(@"RIGHT FOOT ANIMATION STARTING"); 
     [UIView animateWithDuration:15 
           delay:0 
          options: UIViewAnimationOptionCurveLinear | UIViewAnimationOptionBeginFromCurrentState 
         animations:^{ 
          NSLog(@"animating"); 
          self.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(FIRST_ROTATION)); 
         } completion:^(BOOL finished) { 
          [UIView animateWithDuration:15 
                delay:0.5 
               options: UIViewAnimationOptionCurveLinear | UIViewAnimationOptionBeginFromCurrentState 
               animations:^{ 
                self.transform = CGAffineTransformRotate(self.transform, DEGREES_TO_RADIANS(SECOND_ROTATION)); 
               } completion:^(BOOL finished) { 
                [UIView animateWithDuration:15 
                     delay:0.5 
                     options: UIViewAnimationOptionCurveLinear | UIViewAnimationOptionBeginFromCurrentState 
                    animations:^{ 
                     self.transform = CGAffineTransformRotate(self.transform, DEGREES_TO_RADIANS(THIRD_ROTATION)); 
                    }completion:^(BOOL finished) { 
                     [UIView animateWithDuration:15 
                         animations:^{ 
                          self.transform = CGAffineTransformRotate(self.transform, DEGREES_TO_RADIANS(FOURTH_ROTATION)); 
                         }]; 
                    }]; 
               }]; 
         }]; 



    } 
} 

- (void)drawRect:(CGRect)rect 
{ 
    CGFloat x = self.bounds.size.height; 
    CGFloat y = self.bounds.size.width; 

    [[UIColor redColor] setStroke]; 

    UIBezierPath *path = [UIBezierPath bezierPath]; 
    [path moveToPoint:CGPointMake(x/2, y - 20)]; 
    [path addLineToPoint:CGPointMake(x/2 - 10, y)]; 
    [path addLineToPoint:CGPointMake(x/2 + 10, y)]; 
    [path closePath]; 
    [path fill]; 
    //[path stroke]; 

    if (_leftFoot) { 
     self.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(10)); 

    } else { 
     self.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(-10)); 


    } 



} 
+4

그 코드 들여 쓰기가 내 눈을 아프게합니다. 내 심장 –

+0

그 코드 식별은 – Vannian

답변

0

가능한 설명은 FIRST_ROTATION 등 변수에 예기치 않은 값이 있다는 것입니다.

또 하나는 drawRect에서 회전하는 것입니다. 내 마음에는 의도하지 않은 결과가 있습니다. "기본 삼각형"이 직선이 아니길 원한다면 경로에 맞는 점을 계산하고 바로 그립니다.

+0

예요.하지만 외부에서 애니메이션을 호출하는 방법은 무엇입니까? – Vannian

+0

'drawRect' 내부에서 애니메이션을 호출하지 않습니다. – Mundi