scrollable UIView

Discussion in 'iOS Programming' started by sandeepac, Jul 22, 2008.

  1. macrumors newbie

    sandeepac

    Joined:
    Jul 10, 2008
    Location:
    Cochin
    #1
    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
     
  2. macrumors newbie

    Joined:
    Aug 8, 2008
    #2
    Scrollable UIView

    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
     
  3. macrumors newbie

    Joined:
    Mar 20, 2008
    #3
    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...
     
  4. macrumors 65816

    Sbrocket

    Joined:
    Jun 3, 2007
    Location:
    /dev/null
    #4
    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.
     
  5. macrumors newbie

    Joined:
    Feb 5, 2008
    #5
    Sounds like the same problem i had. Make sure you set the contentSize property of the scrollview. That's what fixed it for me.
     
  6. macrumors newbie

    Joined:
    Aug 8, 2008
    #6
    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
     
  7. macrumors member

    Joined:
    Mar 31, 2008
    #7
    ok i figured out what was wrong.

    i was doing this:

    PHP:
    innerview = [[UIView allocinitWithFrame:CGRectZero];
    is seems the frame needs to have its bounds set.
     

Share This Page