开发者

CALayer scale not affected by frame? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 11 years开发者_如何学JAVA ago.

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);   }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜