CALayer scale not affected by frame? [closed]
I'm adding a sublayer with contents of a CGImage. I create it's frame, which i thought included it's bounds and position. I also set the layers contentsGravity, so the image would resize properly in the UIImageView, but the imageview only shows part of the image, indicating that the CALayer didn't scale the image properly. What's really going on here? Why doesn't the CALayer have the right scale?
-(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); }
精彩评论