开发者

Can`t draw in CAlayer

HI All.

I have subclass of UIScrollView. IN this class I have added some imageView.layer to self.layer. And when I call [imageView.layer setNeedsDisplay] my implemented delegate never called.

-(void)drawLayer:(CALayer*)layer :(CGConte开发者_运维知识库xtRef)context 

I`ve also set

imageView.layer.delegate = self

Could anyone tell me where I must set delegate function to make this to work.

Thank you for advance.


There are some things a little bit odd with you approach.

If ou have a ScrollView and an ImageView you don't need to add the layers, you can just do
[scrollView addSubview: imageView];

Also, you don't need a delegate for drawing a UIView into a UIWindow. If, however, you want to add a delegate still you can do this: imageView.delegate = A ImageView should not be his own delegate, you will need some ViewController, better a ScrollViewController.


  1. The method name is -drawLayer:inContext:. The delegate's method signature should be like this:

    //                                  vvvvvvvvv
    - (void)drawLayer:(CALayer *)layer  inContext:(CGContextRef)ctx
    
  2. Don't override the delegate of another layer attached to a view (which is that view). This will make the view cannot operate normally.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜