views:

50

answers:

1

Hi everyone,

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 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!

A: 

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?

tc.
Oh.. you're right. I'd tested it and I thought it didn't change the bounds property but I was wrong. I'm making something similar to the built-in photo app but a UIScrollView inside another UIScrollView sometimes behaves very awkwardly so I wanted to make a custom one. Thanks for the answer!
K J