简体   繁体   中英

how to draw above cashapelayer path

I am having a CAShapeLayer i want to draw above that layer.. I have taken a UIImageView and added on that CAShapelayer and now i starting drawing as user touch moves inside that CAShapelayer path. But when user touch ends i want to merge that drawn image view on CAShape layer in such a way that if users taps again then using hitTest method i can again get the path of cashape layer.

// tempDrawingImage is the image view that i added above hit layer.

UIGraphicsBeginImageContext(tempDrawingImage.frame.size);
        [hitLayer drawInContext:UIGraphicsGetCurrentContext()];
        [tempDrawingImage.image drawInRect:tempDrawingImage.frame];
        hitLayer.contents = (id) UIGraphicsGetImageFromCurrentImageContext().CGImage;
        UIGraphicsEndImageContext();

You cannot easily convert an image to a path for the CAShapeLayer.

You need to have a drawingPath which will be modified according to the touch events. Also a second CAShapeLayer will be needed to draw the current drawingPath (since you will get the same results while drawing as after the merge which is not guaranteed using the image approach). When merging you need to append the drawingPath to the path of your shapeLayer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM