有很多类似的问题,但没有有效的答案。
我要像下面这样向UIView添加新的CALayer:
func placeNewPicture() {
let newPic = CALayer()
newPic.contents = self.pictureDragging.contents
newPic.frame = CGRect(x: pictureScreenFrame.origin.x - pictureScreenFrame.width/2, y: pictureScreenFrame.origin.y - pictureScreenFrame.height/2, width: pictureScreenFrame.width, height: pictureScreenFrame.height)
self.drawingView.layer.addSublayer(newPic)
}
尝试使用以下方法去除它们:
func deleteDrawing() {
for layer in self.drawingView.layer.sublayers {
layer.removeFromSuperlayer()
}
}
成功移除图片,但是应用程序在下一次触摸屏幕时崩溃,并调用主函数,但调试器中没有任何输出。有很多类似的情况,即在移除子层之后不久应用程序将崩溃。
正确的方法是什么,可以从其父视图中移除CALayers?