0

我有一个应该启动动画的功能。三角形是用“drawrect”设计的,我在控制器中有一个按钮,当按下它时,它会调用“startTriangleAnimation”。

问题是“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

1 回答 1

0

一种可能的解释是您的 FIRST_ROTATION 等变量中有意外的值。

另一个是你在drawRect中旋转。在我看来,这会产生意想不到的后果。如果您希望您的“基础三角形”不是直的,只需计算路径的适当点并立即绘制它。

于 2013-03-25T22:36:55.790 回答