[置顶] ios 图片处理-专辑封面头像旋转-裁剪圆形图片

时间:2022-08-11 23:12:58

专辑封面头像旋转

- (void)startAnimation
{imageangle = imageangle+0.5;//全局变量,控制图片每次旋转的角度
CGAffineTransform endAngle = CGAffineTransformMakeRotation(imageangle* (M_PI / 180.0f));

[UIView animateWithDuration:0.01 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
self.bacImage.transform = endAngle;
} completion:^(BOOL finished) {
[self startAnimation];
}];

}

裁剪圆形图片:给UIImage写一个分类

-(UIImage *)circleImage{
/*开启图形上下文*/
UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0);
/*获取图形上下文*/
CGContextRef ctx = UIGraphicsGetCurrentContext();
/*添加一个圆*/
CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
CGContextAddEllipseInRect(ctx, rect);
/*裁剪*/
CGContextClip(ctx);
/*将图片画上去*/
[self drawInRect:rect];
/*获取当前图片*/
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
/*结束图形上下文*/
UIGraphicsEndImageContext();
return image;
}