Drawing incrementally in a UIView (iPhone)

后端 未结 5 1437
甜味超标
甜味超标 2020-12-02 14:09

As far as I have understood so far, every time I draw something in the drawRect: of a UIView, the whole context is erased and then redrawn.

So I have to do something

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-02 14:32

    If you are able to cache the drawing as an image, you can take advantage of UIView's CoreAnimation backing. This will be much faster than using Quartz, as Quartz does its drawing in software.

    - (CGImageRef)cachedImage {
        /// Draw to an image, return that
    }
    - (void)refreshCache {
        myView.layer.contents = [self cachedImage];
    }
    - (void)actionThatChangesWhatNeedsToBeDrawn {
        [self refreshCache];
    }
    

提交回复
热议问题