UIScrollView not scrolling on dynamic height

Discussion in 'iOS Programming' started by bradnet, May 29, 2011.

  1. bradnet, May 29, 2011
    Last edited by a moderator: May 31, 2011

    macrumors newbie

    Joined:
    Mar 8, 2010
    #1
    Hi Guys

    Got a little question that someone may have a simple answer for, i'm using tableview to open a detail view with a scrollview containing an image that could be larger than the page, here is the line that i added

    Code:
    [scrollView setContentSize:CGSizeMake(320, _image.bounds.size.height)];
    using this method the view wont scroll but if i manually specify the height it will scroll fine

    Code:
    [scrollView setContentSize:CGSizeMake(320, 550)];
    my problem is that not all of my images will be 550 heigh some might be over 1000 does anyone know why this isn't working.

    Thanks
    Brad
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Use NSLog to log the image view height when you are using it to set the scrollview content size. It may not be what you expect...
     
  3. thread starter macrumors newbie

    Joined:
    Mar 8, 2010
    #3
    I've checked the NSLog and the size it's outputting is the size of the imageview on the interfacebuilder screen but i want this size to be dynamic to the size of the image i thought this was the correct method.

    Thanks
    Brad
     
  4. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    Then you'll have to set the size of the image view to the size of the image (in the code).
     
  5. thread starter macrumors newbie

    Joined:
    Mar 8, 2010
    #5
    Is there anyway you can point me in the right direction i have an image downloaded from a url and displayed on the screen which is sometimes longer than the screen so i have the mediaURL how would i reference the url to get the image height. is it an NSUrl request.

    Thanks
    Brad
     
  6. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    :confused: You wouldn't. You'd use the obvious method of UIImage.
     
  7. bradnet, May 29, 2011
    Last edited by a moderator: May 31, 2011

    thread starter macrumors newbie

    Joined:
    Mar 8, 2010
    #7
    managed to solve this problem but in order to do it i had to load the data from the url into a nsdata and then load this data into a uiimage and then measure the UIImage.

    Here's the code to help any others out
    Code:
    NSString * mediaUrl = [[[self appDelegate]currentlySelectedBlogItem]mediaUrl];
    NSData* imageData;
    imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:mediaUrl]];			
    UIImage * imageFromImageData = [[UIImage alloc] initWithData:imageData];
    NSLog(@"DetailScreen applicationFrameSize: %.0f", imageFromImageData.size.height);
    [scrollView setContentSize:CGSizeMake(320, imageFromImageData.size.height)];
    Thanks
    for the help
     

Share This Page