PDA

View Full Version : scrollable UIView




sandeepac
Jul 22, 2008, 08:51 AM
Hi All

Is there any sample code for Scrollable UIView (which is a subview with some drawings inside).

I made a custom UIScrollView and made it the superview of my UIView.
But it is not working.

Regards
Sandeep



Shrunga
Aug 8, 2008, 05:18 AM
Hi,

Im a newbie to Iphone programming and I too Im working on the same without any success.

Has anyone found a solution for this ?
If so kindly post some pointers..

Regards,
Shruga

PhilNash
Aug 10, 2008, 10:43 AM
Hi All
I made a custom UIScrollView and made it the superview of my UIView.


That's a good start. You'll also need to implement a UIScrollViewDelegate and at least the scrollViewDidScroll method on it.

You say it "doesn't work" - can you be any more specific?
Do you get content but it doesn't scroll?
Do you get no content?
Does it scroll but not zoom?
etc...

Sbrocket
Aug 10, 2008, 01:32 PM
That's a good start. You'll also need to implement a UIScrollViewDelegate and at least the scrollViewDidScroll method on it.

A delegate is not required for UIScrollView. The only time you'll "need to implement" one is if you need to perform sometimes in one of the methods provided by the UIScrollViewDelegate protocol.

---

Most people forget to set the contentSize property properly when using a UIScrollView. Other than that, you aren't giving us any information with which to help you. "It's not working" is not going to get you any targeted answers.

seventoes
Aug 10, 2008, 06:00 PM
Hi All

Is there any sample code for Scrollable UIView (which is a subview with some drawings inside).

I made a custom UIScrollView and made it the superview of my UIView.
But it is not working.

Regards
Sandeep

Sounds like the same problem i had. Make sure you set the contentSize property of the scrollview. That's what fixed it for me.

Shrunga
Aug 10, 2008, 11:10 PM
Sounds like the same problem i had. Make sure you set the contentSize property of the scrollview. That's what fixed it for me.

Yes! :)
Here is what i did and it works perfectly fine for me now. Make sure that your custom view's frame is larger than scrollview's frame. This is what was stopping my scroller from getting displayed.
Thank you all.

UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:[MyView frame]];//(0,0,320,160)
scrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

[MyView setFrame:CGRectMake (0, 0, 320, 170)];
MyView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
scrollView.contentSize = MyView.bounds.size;


scrollView.bounces = YES;
scrollView.bouncesZoom = YES;
scrollView.scrollEnabled = YES;
scrollView.minimumZoomScale = 0.5;
scrollView.maximumZoomScale = 5.0;
scrollView.delegate = self;

[scrollView addSubview: MyView];
[self.view addSubview:scrollView];

Thanks and Regards,
Shrunga

springframework
Aug 11, 2008, 12:15 PM
ok i figured out what was wrong.

i was doing this:


innerview = [[UIView alloc] initWithFrame:CGRectZero];


is seems the frame needs to have its bounds set.