[英]Rotation UIImageView around An anchorPoint
我想圍繞錨點旋轉多個UIImageView並給它們一點旋轉,所以可能是這樣的
這是我的代碼,我認為應該可以,但是磨損了
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增加角度在同一側,如何實現呢?
這是由於CGAffineTransformMakeRotation()
將弧度作為輸入而非度數的事實。 現在,您可以使用如下宏輕松地將度數轉換為弧度:
#define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI)
或者,您可以只使用較小的輸入值。 在弧度中,360度等於2 *π〜6.28,因此,應該假設0-2π而不是假設0-360范圍內的值。 當您將值增加3時,實際上就是將其增加了將近180度,這就是為什么您看到自己的樣子的原因。
總體而言,嘗試使用angel += 0.052539;
。 正如@Kyle W.指出的那樣,您需要將angel
從int更改為float。
我不確定我是否理解您的問題,但是請嘗試以下操作:
將角度從int
更改為float
。
float angel = 0;
更改循環的每次迭代的增量。
angel += 0.3;
另外,我認為您的意思是“角度”而不是“天使”;)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.