在iphone中如何讓某個uiview順著某個圓心轉
首先定義,把角度轉換成弧度
#define RADIANS( degrees ) ( degrees * M_PI / 180 )
[NSTimer scheduledTimerWithTimeInterval:0.01f
target:self
selector:@selector(testeeee)
userInfo:nil
repeats:YES];
-(void) testeeee{
if (angle > 360) {
angle = 0;
}
angle++;
// NSLog(@"%f",angle);
int r = 100;
// testView.frame = CGRectMake(120, 120, 50, 50);
CGPoint newCarPosition;
newCarPosition.x = (160) + r*cos(RADIANS(angle));
newCarPosition.y = (230) + r*sin(RADIANS(angle));
CGRect new = touchView.frame;
new.origin = newCarPosition;
touchView.frame = new;
}
留言
張貼留言