【问题标题】:Animate UIView calling a method动画 UIView 调用方法
【发布时间】:2013-03-25 18:03:25
【问题描述】:

我有一个应该启动动画的功能。三角形是用“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));


    }



}

【问题讨论】:

  • 那个代码缩进伤害了我的眼睛......和我的心
  • 这是 xcode 标识

标签: ios uiview uiviewanimation


【解决方案1】:

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

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

【讨论】:

  • 是的,但是如何从外部调用动画?
  • 你没有从drawRect内部调用动画。
猜你喜欢
  • 2017-10-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-11
  • 2014-09-16
  • 2014-05-13
  • 1970-01-01
相关资源
最近更新 更多