나는 당신과 같은 문제가있어 해결책을 찾았습니다! 내가 애니메이션을 가지고 있기 때문에 UIImageView
을 회전시키고 싶습니다.나는이 방법을 사용하여 이미지를 저장하려면 :
void CGContextConcatCTM(CGContextRef c, CGAffineTransform transform)
이 PARAM을 변환하면 이미지와 동일합니다 당신이 이미지 뷰에했던 당신의 UIImageView
그래서 아무것도 변환입니다! 그리고 나는 UIImage
이라는 카테고리 메소드를 작성했습니다.
-(UIImage *)imageRotateByTransform:(CGAffineTransform)transform{
// calculate the size of the rotated view's containing box for our drawing space
UIView *rotatedViewBox = [[UIView alloc] initWithFrame:CGRectMake(0,0,self.size.width, self.size.height)];
rotatedViewBox.transform = transform;
CGSize rotatedSize = rotatedViewBox.frame.size;
[rotatedViewBox release];
// Create the bitmap context
UIGraphicsBeginImageContext(rotatedSize);
CGContextRef bitmap = UIGraphicsGetCurrentContext();
// Move the origin to the middle of the image so we will rotate and scale around the center.
CGContextTranslateCTM(bitmap, rotatedSize.width/2, rotatedSize.height/2);
//Rotate the image context using tranform
CGContextConcatCTM(bitmap, transform);
// Now, draw the rotated/scaled image into the context
CGContextScaleCTM(bitmap, 1.0, -1.0);
CGContextDrawImage(bitmap, CGRectMake(-self.size.width/2, -self.size.height/2, self.size.width, self.size.height), [self CGImage]);
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
희망이 도움이 될 것입니다.
CGAffineTransformScale (기존 변환을 시작점으로 사용하여 변형을 만들 수 있음)과 같은 함수도 살펴볼 수 있습니다. –
안녕하세요 Christopher, 응답 해 주셔서 감사합니다. 원래 게시물에서 언급 한 것처럼 내 문제는 이미지를 수직으로 뒤집어 씌우려 고합니다 (UIImageview 내부 이미지의 이미지를 대칭). 원래 게시물에 게시 된 코드 스 니펫은 정상적으로 작동하지만 UIImageview의 새로운 (뒤집힌) 상태 또는 변환을 저장하지 않습니다. 한 번 뒤집었기 때문에 뒤집힌 이미지에서 더 많은 회전을하고 싶습니다. 내가 뒤집어서 회전한다고 말하면 위의 코드로 UIImageview를 뒤집습니다. 회전을 클릭하면 뒤집힌 것이 아니라 원래 UIImageview가 회전합니다. 나는 당신을 혼란스럽게하지 않았 으면 좋겠다. –