0
我需要使用contentMode UIViewContentModeTopLeft在UIImageView中居中并缩放UIImage,只需使用CGAffineTransform。我无法使用contentMode UIViewContentModeCenter,因为我需要完整的CGAffineTransform信息。如何在UIImageView中居中缩放(旋转)UIImage
到目前为止,我正在使用类似这样的地方_imageView是一个UIImageView和图像的UIImage。
_imageView.image = image;
CGFloat scale = fmaxf(_imageView.bounds.size.width/_imageView.image.size.width, _imageView.bounds.size.height/_imageView.image.size.height);
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformTranslate(transform, _imageView.image.size.width * 0.5, _imageView.image.size.height * 0.5);
transform = CGAffineTransformScale(transform, scale, scale);
_imageView.transform = transform;
缩放比较好,但图像总是偏右下角。 有没有人知道如何做到这一点,而不使用contentMode UIViewContentModeCenter?
您也可以尝试与CALayer的其[anchorPoint]玩(https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreAnimation_guide/ CoreAnimationBasics/CoreAnimationBasics.html#// apple_ref/DOC/UID/TP40004514-CH2-SW15)。 – 2013-03-07 21:36:41