ios - CALayer Troubles when loading an image from a UIImagePicker -
i have uiviewcontroller uiimageview (imageview), , i'm defining several layers nested in imageview follows in viewdidload:
//container layer - top layer calayer *containerlayer = [calayer layer]; containerlayer.opacity = 0; containerlayer.bounds = [self.imageview.layer frame]; // holder layer calayer *holderlayer = [calayer layer]; holderlayer.opacity = 0; holderlayer.bounds = self.imageview.bounds; // hierarchy layers [containerlayer setvalue:holderlayer forkey:@"__holderlayer"]; [containerlayer addsublayer:holderlayer]; [self.imageview.layer addsublayer:containerlayer];
i have following code works when loading image uiimagepicker :
uiimage *image = [info objectforkey:uiimagepickercontrolleroriginalimage]; uiimageview *newimgview = [[uiimageview alloc] initwithframe:self.imageview.frame]; cgrect frame = self.imageview.frame; newimgview.image = image; frame.origin = cgpointmake(0, 0); newimgview.layer.frame = frame; newimgview.layer.opacity = .9; newimgview.layer.contentsgravity = kcagravityresizeaspectfill; calayer * containerlayer = self.imageview.layer.sublayers[0]; if (containerlayer != nil) { [containerlayer setvalue:newimgview.layer forkey:@"__imagelayer"]; calayer * holderlayer = [containerlayer valueforkey:@"__holderlayer"]; if (holderlayer != nil) { //!!!!!line below doesn't work!!! //[holderlayer addsublayer:newimgview.layer]; //line below works! [self.imageview.layer addsublayer:newimgview.layer]; } } [self.imageview setneedsdisplay]; [self checkandprintlayers];
so first nested layer containerlayer, holderlayer, , i'm expecting add various images sublayers holderlayer , manipulate it. however, calling
[holderlayer addsublayer:newimgview.layer];
doesn't work; imageview stays blank. however, calling
[self.imageview.layer addsublayer:newimgview.layer];
and adding sublayer top layer works dandy. missing obvious here? love suggestions. thanks.
because
holderlayer , containerlayer transparent (holderlayer.opacity = 0 / containerlayer.opacity = 0),
make it,
//container layer - top layer calayer *containerlayer = [calayer layer]; containerlayer.opacity = 1.0; containerlayer.bounds = [self.imageview.layer frame]; // holder layer calayer *holderlayer = [calayer layer]; holderlayer.opacity = 1.0; holderlayer.bounds = self.imageview.bounds;
Comments
Post a Comment