开发者

iphone image move like another image

开发者 https://www.devze.com 2023-02-26 02:44 出处:网络
I have an image which is rotating and what I want is that a second image to be stuck on it and it rotate just as the first. Please, how can I d开发者_开发百科o this?I\'m not at my computer so I can\'t

I have an image which is rotating and what I want is that a second image to be stuck on it and it rotate just as the first. Please, how can I d开发者_开发百科o this?


I'm not at my computer so I can't test this, but I think it should get you what you want.

// assuming you already have your views
// viewOne, viewTwo

[viewOne addSubview:viewTwo]; // add viewTwo to viewOne

// let's assume that you call this code here one time per second
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];

// when this is 1.0, the image will rotate 360
// ... when it is .5, it should rotate 180, etc...
float rotationFactor = 0.1f;

// viewTwo's rotationFactor will be added to view 1's in the transform below
float rotationFactor2 = 0.1f;

viewOne.transform = CGAffineTransformMakeRotation(M_PI_2 * rotationFactor);
viewTwo.transform = CGAffineTransformMakeRotation(M_PI_2 * (rotationFactor + rotationFactor2);

[UIView commitAnimations];
0

精彩评论

暂无评论...
验证码 换一张
取 消