【问题标题】:Scale animation in background from another anchorPoint从另一个锚点缩放背景中的动画
【发布时间】:2015-10-28 08:15:32
【问题描述】:

我已经为带有箭头的背景图像做了一个缩放动画,通过缩放图像(它包括箭头)意味着它是一个完整的背景。它从背景的中心缩放。但我想从箭头的中心开始缩放。

我想实现这个:

然后变成与规模:

我必须在代码中更改的内容:

    self.blueBackground.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1, 1);
    [UIView animateWithDuration:5 animations:^{
        self.blueBackground.transform = CGAffineTransformScale(CGAffineTransformIdentity, 30, 30);

    } completion:^(BOOL finished) {

    }];

使用我当前的代码,比例从背景中心开始,所以箭头最终在右侧(屏幕边界外)。

【问题讨论】:

    标签: ios objective-c animation cgaffinetransformscale


    【解决方案1】:

    试试这样的:

    - (void)animateArrow
    {
      self.blueBackground.transform = CGAffineTransformIdentity;
      [UIView animateWithDuration:5 animations:^{
        ScaleViewAboutPointInBounds(self.blueBackground, arrowCenter, 30);
      } completion:^(BOOL finished) {
      }];
    }
    
    static void ScaleViewAboutPointInBounds(UIView *view, CGPoint point, CGFloat scaleAmount)
    {
      CGFloat xAnchor = view.layer.anchorPoint.x * CGRectGetWidth(view.bounds);
      CGFloat yAnchor = view.layer.anchorPoint.y * CGRectGetHeight(view.bounds);
    
      CGFloat xOffset = point.x - xAnchor;
      CGFloat yOffset = point.y - yAnchor;
    
      CGAffineTransform shift = CGAffineTransformMakeTranslation(-xOffset, -yOffset);
      CGAffineTransform unshift = CGAffineTransformMakeTranslation(xOffset, yOffset);
      CGAffineTransform scale = CGAffineTransformMakeScale(scaleAmount, scaleAmount);
    
      view.transform = CGAffineTransformConcat(shift, CGAffineTransformConcat(scale, unshift));
    }
    

    它可能比您需要的更通用,您可以更简单地完成它,但这也应该有效。只需将point 更改为看起来像箭头中心的东西。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-21
      • 1970-01-01
      • 2014-05-17
      • 2013-07-25
      • 2014-08-26
      • 2020-10-13
      相关资源
      最近更新 更多