UIScrollView

Discussion in 'iOS Programming' started by KardelSharpeye, May 11, 2009.

  1. KardelSharpeye macrumors member

    KardelSharpeye

    Joined:
    Apr 28, 2009
    #1
    Hello,

    does anyone know how to get the UIViewImage or the content inside of a UIScrollView after you add the image to the subview of the UIScrollView.

    So if i have
    UIViewImage *image;
    UIScrollView *view;
    [view addSubView:image]

    anyone know how i can extract the image?
     
  2. Niiro13 macrumors 68000

    Joined:
    Feb 12, 2008
    Location:
    Illinois
    #2
    Well, you can do it three ways.

    You can simply go [view.subviews objectAtIndex:0] (note that it won't always be 0 depending on the order you added the views to the scrollview).

    You can make the image an instance variable (put it in the header file) and access it that way instead of calling it from the scrollview.

    You can subclass scrollview, add the image there, then make the image an instance variable.
     
  3. KardelSharpeye thread starter macrumors member

    KardelSharpeye

    Joined:
    Apr 28, 2009
    #3
    cool i am implementing your first method, however, i am not sure if it works yet so far there is no bug.

    i am however having trouble with the pinching it doesnt seem to do anything to the image.

    here is what i got:
    UIImageView tempImage = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0 70.0, 70.0)];
    tempImage.image = [[UIImage imageNamed:mad:"image.jpg"];
    [tempImage setOpaque:YES];
    [tempImage setUserInteractionEnabled:YES];

    UIScrollView scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0 70.0, 70.0)];
    scrollView.contentSize = CGSizeMake(70, 70);
    scrollView.clipsToBounds = YES;
    [scrollView setUserInteractionEnabled:YES];

    [scrollView addSubview:tempImage];
    [self addSubview:scrollView];

    [tempImage release];
     
  4. Niiro13 macrumors 68000

    Joined:
    Feb 12, 2008
    Location:
    Illinois
    #4
    Hi! For zooming, you need to set more things.

    You need to set the maximumZoomScale and minimumZoomScale (by default they're both 1.0, so it wouldn't zoom).

    Then implement the viewForZoomingInScrollView method (part of the UIScrollViewDelegate) and return the imageView ([scrollView.subviews objectAtIndex:0] if you didn't set the imageView as an instance variable).

    Lastly, you probably want to implement the scrollViewDidEndZooming in order to set the contentSize.
     

Share This Page