3

私は CGAffineTransforms を研究してきましたが、ビューを取得して x、y 座標にズームインする方法があるかどうか疑問に思っていました。関数でスケーリング部分を縮小しました:

       CGAffineTransformMakeScale(4.00 ,4.00);

ただし、スケーリングを可能なx、y座標と結び付ける方法がわかりません。誰かがこのようなことをしたことがありますか?これらの関数の使用法が間違っている可能性がありますか?

       -(void)buttonSelected:(id)sender
       {
          UIButton *b = sender;
          CGPoint location = b.frame.origin;

          [UIView animateWithDuration:1.3f delay:0.0f options:UIViewAnimationCurveEaseIn animations:^{
               CGAffineTransform totalTransform =
               CGAffineTransformMakeTranslation(-location.x  , -location.y );
               totalTransform = CGAffineTransformScale(totalTransform, 4.0f, 4.0f);
               totalTransform = CGAffineTransformTranslate(totalTransform, location.x , location.y );
               [self.view setTransform:totalTransform];
           }completion:^(BOOL finished) {
           }];

       }
4

1 に答える 1

5

次の3つのステップを実行する変換を作成します。

  • スケールするポイントをレイヤーの中心に移動します。
  • 規模;
  • 元の中心が中心に戻るようにオブジェクトを戻します。

だから、例えば

// to use a point that is (109, 63) from the centre as the point to scale around
CGAffineTransform totalTransform =
                  CGAffineTransformMakeTranslation(-109.0f, -63.0f);
totalTransform = CGAffineTransformScale(totalTransform, 4.0f, 4.0f);
totalTransform = CGAffineTransformTranslate(totalTransform, 109.0f, 63.0f);

または、おそらくもっと簡単にview.layer'sを調整しanchorPointます。2番目のアイデアの落とし穴は、最初にアンカーポイントを調整すると、他のすべての配置が中心に基づいているため、すぐに変換されるということです。

于 2013-01-28T20:31:36.810 に答える