UIImageView Size Problem

Discussion in 'iOS Programming' started by loon3y, Dec 21, 2011.

  1. loon3y macrumors 65816

    loon3y

    Joined:
    Oct 21, 2011
    #1
    In my app i call a an image to from a web service to show up in my image view.

    after i implemented the zoom for my image view and scrollview, when i get the image it comes out shrunk at the top left hand corner.


    how can i get it so it fills up the UIImageView?? and make the zoom and zoom out centered?
     
  2. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    Providing us with the relevant source code would be most useful in helping you...
     
  3. loon3y thread starter macrumors 65816

    loon3y

    Joined:
    Oct 21, 2011
    #3


    ohh sorry forgot about that


    Code:
    
    - (void)viewDidLoad
    {
        NSLog(@"viewDidLoad");
        [super viewDidLoad];
    	// Do any additional setup after loading the view, typically from a nib.
        [scrollView setScrollEnabled:YES];
        scrollView.contentSize = productImage.frame.size;
        scrollView.minimumZoomScale = 0.4;
    	scrollView.maximumZoomScale = 4.0;
        scrollView.delegate = self;
    	[scrollView setZoomScale:scrollView.minimumZoomScale];
        scrollView.frame = CGRectMake (0, 0, 320, 460);
        [scrollView setContentSize:CGSizeMake(320, 600)];
    }
    
    -(UIView *) viewForZoomingInScrollView:(UIScrollView *)inScroll 
    {
        return productImage;
    }
    
    
    
    
     
  4. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #4
    The two lines I bolded strike me as odd... doesn't the second make it so the first effectively isn't there?

    What happens if you just get rid of the second? (That's a question, not an answer... I have no idea what will happen, but I hope it's closer to what you want.)

    As far as forcing it to remain centered as you zoom and zoom out... you might want to look into adjusting the scroll view's content offset property based on the current zoom to make sure it's centered... I can't think of what the exact equation would be right now...
     
  5. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #5
    Yeah, you are overriding the size of your CONTENT frame, not of your actual frame.
    This will cause for unwanted behaviour, because you can scroll further then the actual image.
     

Share This Page