Using CALayer Delegate

前端 未结 8 1089
滥情空心
滥情空心 2020-12-02 08:44

I have a UIView whose layers will have sublayers. I\'d like to assign delegates for each of those sublayers, so the delegate method can tell the layer what to draw. My que

8条回答
  •  北海茫月
    2020-12-02 09:24

    A note regarding "helper" classes for use as a layer's delegate (with ARC at least):

    Make sure you store a "strong" reference to your alloc/init'd helper class (such as in a property). Simply assigning the alloc/init'd helper class to the delegate seems to cause crashes for me, presumably because mylayer.delegate is a weak reference to your helper class (as most delegates are), so the helper class gets freed up before the layer can use it.

    If I assign the helper class to a property, then assign it to the delegate, my weird crashes go away, and things behave as expected.

提交回复
热议问题