Reputation: 289
i want to rotate multiple UIImageView around anchor point and give them a little rotation so that could be something like this
this is my code i think it should work but wear thing happened
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;
}
i think they all should be in the same side as iam increasing angle with 3 , how to achieve this ?
Upvotes: 1
Views: 1081
Reputation: 130222
This is due to the fact that CGAffineTransformMakeRotation()
takes radians as input, not degrees. Now, you could easily convert from degrees to radians using a macro like this:
#define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI)
Or you could just use smaller input values. In radians, 360 degrees is equal to 2 * π ~ 6.28, so instead of ranging your values assuming 0-360, you should assume 0-2π. When you increase the value by 3, you're effectively increasing it by just under 180 degrees, which is why you're seeing what you are.
Overall, try using angel += 0.052539;
. You'll need to change angel
from an int to a float as @Kyle W. pointed out
Upvotes: 1
Reputation: 3790
I'm not entirely sure I understood your question, but try this:
Change the angle from an int
to a float
.
float angel = 0;
Change the increment for each iteration of the loop.
angel += 0.3;
Also, I think you mean "angle" not "angel" ;)
Upvotes: 1