圆周。线程

{

NSMutableArray *_array;

}


- (void)viewDidLoad {

[super viewDidLoad];

_array= [[NSMutableArray alloc] initWithCapacity:0];

for(inti = 0; i < 9; i ++) {

UIImageView *galaxy = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2-10, self.view.frame.size.height/2-10, 20, 20)];

galaxy.image= [UIImage imageNamed:@"26.png"];

[self.view addSubview:galaxy];

[_array addObject:galaxy];

}

NSLog(@"%@",_array);

[NSThread detachNewThreadSelector:@selector(move) toTarget:self withObject:nil];

}

- (void)move {

for(; ; ) {

[self performSelectorOnMainThread:@selector(freshUI) withObject:self waitUntilDone:YES];

[NSThread sleepForTimeInterval:0.5];

}

}

-(void)freshUI {

static float angle = 0;

for(int i = 0; i < 9; i ++) {

UIImageView *galaxy =_array[i];

angle += 3;

float x = 160 + 40 * (i+1) *cos((i + 1) * angle *M_PI/ 180);

float y = 240 - 40 * (i+1) *sin((i + 1) * angle *M_PI/ 180);

galaxy.center=CGPointMake(x, y);

}

}


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容