나는 이미지를로드하고이 방법으로 거울을 만들 : drawRect를 사용하여 UIView에서 대칭 UIImage를 그리는 방법은 무엇입니까?
originalImg = [UIImage imageNamed:@"ms06.png"];
mirrorImg = [UIImage imageWithCGImage:[originalImg CGImage] scale:1.0 orientation:UIImageOrientationUpMirrored];
가 그럼 난에 UIView의 하위 클래스에 위에있는 UIImage 객체를 설정하고의 drawRect 오버라이드 (override) : 없음 문제
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGAffineTransform t0 = CGContextGetCTM(context);
CGContextConcatCTM(context, t0);
CGContextDrawImage(context, self.bounds, [image CGImage]);
CGContextRestoreGState(context);
}
을하는 이미지 내가 그려, 표시되는 이미지는 항상 원래 하나의 UIView 하위 클래스로 설정하면 미러 된 이미지가 표시되지 않습니다. 원본 이미지가 0 인 동안 "UIImageOrientationUpMirrored"를 의미하는 방향 멤버 변수가 4와 같음을 디버그 정보에 표시했기 때문에 미러 된 이미지가 UIView에 올바르게 설정되었는지 확신합니다. 누구나 나를 도울 수 있습니까? 이 문제는, 고마워.
또한 setImage :를 사용하여 UIImageView에서 미러 된 이미지를 표시하려고 시도했으며 올바르게 작동합니다. 그런데 UIImageView의 setImage를 호출 할 때 drawRect의 중단 점이 결코 부딪치지 않는다는 것을 알았습니다. UIImageView에 이미지를로드 할 때 그리기 동작 (예 : 이미지 위의 선 그리기)을 어떻게 정의 할 수 있습니까?
은 당신의 코드를 변경하십시오 (있는 UIImage + Rotating.m 참조), '[있는 UIImage imageWithCGImage : [originalImg의 CGImage] 크기 : 1.0 방향 : UIImageOrientationRightMirrored]; ' OR '[UIImage imageWithCGImage : [originalImg CGImage] 크기 : 1.0 orientation : UIImageOrientationLeft];' – Dhruv
응답 해 주셔서 감사합니다. –
미러링 된 이미지가 필요한 경우 초기 코드만으로 충분합니다. 왜 drawrect 메서드를 사용하고 싶습니까? – Dhruv