2013-03-25 23 views
0

我有一個函數應該開始動畫。三角形設計爲「drawrect」,我在控制器中有一個按鈕,當它被按下時,它會調用「startTriangleAnimation」。動畫UIView調用metod

問題是方法「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

這段代碼壓痕傷害了我的眼睛......和我的心臟 – 2013-03-25 18:04:33

+0

這是xcode的身份 – Vannian 2013-03-25 18:09:27

回答

0

一個可能的解釋是,您在FIRST_ROTATION等變量中有意想不到的值。

另一個是你在drawRect中旋轉。在我看來,這有意想不到的後果。如果你想讓你的「底座三角形」不是直的,只需爲你的路徑計算適當的點並立即繪製。

+0

你好但是如何從外部調用動畫? – Vannian 2013-03-26 07:36:33

+0

你不是從'drawRect'裏面調用動畫。 – Mundi 2013-03-26 22:29:46