How do I use CALayer with the iPhone?

后端 未结 3 1649
余生分开走
余生分开走 2021-02-10 18:05

Currently, I have a UIView subclass that \"stamps\" a single 2px by 2px CGLayerRef across the screen, up to 160 x 240 times.

I currently animate this by moving the UIVie

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-10 18:15

    What CALayer methods are you seeing that don't work on iPhone?

    As one example, I tried implementing the grid demo here, without much luck. It looks like CAConstraintLayoutManager and CAConstraint are not available in QuartzCore.h.

    In another attempt, I tried a very simple, small 20x20 CALayer object as a sublayer of my UIView's layer property, but that didn't show up.

    Right now, I have a custom UIView of which I override the drawRect method. In drawRect I grab a context and render two types of CGLayerRefs:

    At "off" cells I draw the background color across the entire 320x480 canvas.

    At "on" cells, I either draw a single CGLayerRef across a grid of 320x480 pixels (initialization) or across a 320x2 row (animation).

    During animation, I make a UIImageView clip view from 320x478 pixels, and draw a single row. This "pushes" my bitmap up the screen two pixels at a time.

    Basically, I'd like to test whether or not using CALayer will accomplish two things:

    1. Make my rendering faster, if CALayer has less overhead than what I'm doing now
    2. Make my animation smoother, by letting me transition a layer up the screen smoothly

    Unfortunately, I can't seem to get a basic CALayer working at the moment, and haven't found a good chunk of sample code to look at and play with.

提交回复
热议问题