闲话少说,直接上代码!
UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, imageBgWH, imageBgWH)];
imageView.image=[UIImage imageNamed:@"testing_tree"];
imageView.center=imageBg.center;
// NSLog(@"%f",imageView.top);
[self.view addSubview:imageView];
添加要旋转的图片
- (CADisplayLink *)link
{
if (!_link) {
self.link = [CADisplayLink displayLinkWithTarget:self selector:@selector(up)];
}
return _link;
}
懒加载link
[self.link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
- (void)up
{
// 1/60秒 * 45
// 规定时间内转动的角度 == 时间 * 速度
CGFloat ang = self.link.duration * M_PI_2;
imageBg.transform = CGAffineTransformRotate(imageBg.transform, ang);
}
新手分享,勿喷!
时间: 2024-10-22 00:44:33