2014-07-24 52 views
1

我在重复/倒转动画中使用仿射变换来创建“脉动”效果。但是,我注意到动画开始时按钮会右移。按钮的锚固点是(0.5,0.5):iOS如何从视图中心动画视图缩放?

[UIView animateWithDuration:0.5 
          delay:0 
         options:UIViewAnimationOptionRepeat| 
    UIViewAnimationOptionAutoreverse| 
    UIViewAnimationOptionAllowUserInteraction| 
    UIViewAnimationCurveEaseInOut 
        animations:^{ 
         self.recordButton.transform = CGAffineTransformMakeScale(1.2, 1.2); 
        } completion:^(BOOL finished) { 

        }]; 

似乎被应用的变换时,该按钮的坐标系的原点保持在同一地点。

如何动画缩放变换,以便在应用变换后按钮的中心保持在同一个点上?

回答

0

我通常与框架和的CGRect实用功能发挥

[UIView animateWithDuration:0.5 
         delay:0 
        options:UIViewAnimationOptionRepeat| 
UIViewAnimationOptionAutoreverse| 
UIViewAnimationOptionAllowUserInteraction| 
UIViewAnimationCurveEaseInOut 
       animations:^{ 
        self.recordButton.frame = CGRectInset(self.recordButton.frame, -1.2, -1.2); 
       } completion:^(BOOL finished) { 

       }];