我正在添加一个包含CGImage内容的子图层。我创建了它的框架,我认为它包含了它的边界和位置。我还设置了图层contentsGravity,因此图像会在UIImageView中正确调整大小,但imageview只显示部分图像,表明CALayer没有正确缩放图像。这里到底发生了什么?为什么CALayer没有合适的比例?
-(void)setImageInView:(UIImage*)img {
CALayer *mosaicLayer = [CALayer layer];
mosaicLayer.frame = CGRectMake(0.0f,0.0f, 720.0f, 960.0f);
mosaicLayer.contentsGravity = kCAGravityResizeAspect;
mosaicLayer.contents = (id)[img CGImage];
[imageView.layer addSublayer:mosaicLayer];
UIGraphicsBeginImageContext(mosaicLayer.bounds.size);
[mosaicLayer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *saver = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(saver, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); }