开发者

Implementing a custom UIScrollView

I'm trying to implement a custom UIView that mimics the behavior of UIScrollView for some reason. And the question is how can I show the proper part of the content which is represented by the contentOffset property?

I've analyzed UIScrollView and found that it doesn't adopt any inbetween sublayers or manipulate the bounds and transform properties to apply the offset. I've开发者_Go百科 overridden the UIView``'s drawRect: method as follows but it didn't work:

- (void)drawRect: (CGRect)rect {
  CGContextRef context = UIGraphicsGetCurrentContext();
  CGContextTranslateCTM(context, -content_offset_.x, -content_offset_.y);
}

So my question is how does UIScrollView show the proper part of its content? Should I override the layer's display method or else? Any suggestions would be appreciated! And please don't ask 'why do you want to do anything like that in the first place?' :D

Thanks!


UIScrollView changes its bounds (it moves the origin around).

-drawRect: is called to draw your layer's content and does not affect sublayers. You're not drawing anything.

I'd just use a UIScrollView though. What are you doing that UIScrollView doesn't?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜