【问题标题】:Rotation UIImageView around An anchorPoint围绕 An anchorPoint 旋转 UIImageView
【发布时间】:2013-09-01 21:51:37
【问题描述】:

我想围绕锚点旋转多个 UIImageView 并给它们一点旋转,这样就可以是这样的

https://www.google.com.eg/search?q=cards.&um=1&ie=UTF-8&hl=en&tbm=isch&source=og&sa=N&tab=wi&ei=zzkjUoXFL5GWswbrrIGgBw&biw=1024&bih=615&sei=0TkjUu2wHcmntAbC54Bo#facrc=&imgdii=&imgrc=BdArJtkexKgyQM%3A%3BnKsOa4ZSkOOFcM%3Bhttp%253A%252F%252Fdailywicca.com%252Fwp-content%252Fuploads%252F2011%252F10%252Fplaying-cards1.jpg%3Bhttp%253A%252F%252Fdailywicca.com%252F2011%252F10%252F08%252Freading-with-a-plain-deck-of-cards%252F%3B1920%3B1200

这是我的代码,我认为它应该可以工作,但发生了磨损

int angel=0;

for (int i=0; i<6; i++)
{
    UIImage *image=[UIImage imageNamed:@"images.jpeg"];
    UIImageView *imageView=[[UIImageView alloc]initWithImage:image];
    [self.view addSubview:imageView];
    [imageView setFrame:CGRectMake(0, 0, 80, 80)];
    [imageView setCenter:CGPointMake(150, 150)];
    imageView.layer.anchorPoint = CGPointMake(1.0, 1.0);
    imageView.transform = CGAffineTransformMakeRotation(angel);

    angel+=3;
}

我认为它们都应该在 iam 以 3 增加角度的同一侧,如何实现这一点?

【问题讨论】:

    标签: ios


    【解决方案1】:

    这是因为CGAffineTransformMakeRotation() 将弧度作为输入,而不是度数。现在,您可以使用如下宏轻松地将度数转换为弧度数:

    #define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI)
    

    或者您可以只使用较小的输入值。以弧度表示,360 度等于 2 * π ~ 6.28,因此不要将值范围假设为 0-360,而应假设为 0-2π。当您将值增加 3 时,您实际上将其增加了不到 180 度,这就是您看到自己的原因。

    总的来说,尝试使用angel += 0.052539;。正如@Kyle W. 指出的那样,您需要将angel 从int 更改为float

    【讨论】:

      【解决方案2】:

      我不完全确定我理解了你的问题,但试试这个:

      将角度从int 更改为float

      float angel = 0; 
      

      为循环的每次迭代更改增量。

      angel += 0.3;
      

      另外,我认为您的意思是“角度”而不是“天使”;)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-05
        • 2021-09-13
        相关资源
        最近更新 更多