如何在这个轨迹上移动uiview

时间:2013-02-19 20:16:14

标签: ios cocoa uiimage anchor

你能解释我如何旋转图像使用锚点,如

https://www.dropbox.com/s/vh3h5cr1mkdbfh3/ex_image2.JPG

on .m

#import <QuartzCore/QuartzCore.h>

on .h

[UIView animateWithDuration:0.7f
                          delay:0
                        options:UIViewAnimationOptionCurveEaseOut
                     animations:^
     {
         self.center = position;
         self.layer.anchorPoint = CGPointMake(-1, 0);
         self.transform = CGAffineTransformMakeRotation(-5);

     }
                     completion:^(BOOL completed){

                     }];

当我使用这段代码时,我有类似的东西

https://www.dropbox.com/s/v87abux9dqm4y0p/ex_image1.JPG

1 个答案:

答案 0 :(得分:0)

将旋转变换应用于图层时,旋转会在定位点周围发生。

首先将图层的锚点设置为(0.0,0.0)。

self.layer.anchorPoint = CGPointMake(0.0f, 0.0f);

然后你可以旋转视图,旋转将发生在锚点周围,(0.0,0.0)。

[UIView animateWithDuration:2.0f animations:^{
    self.transform = CGAffineTransformMakeRotation(3.1415f);
}];

代码将以您拍摄的方式一次旋转视图。

您可以查看the section titled "Anchor Points Affect Geometric Manipulations" in Apple's "Core Animation Programming Guide"了解详情。