PDA

View Full Version : UIScrollView not scrolling on dynamic height




bradnet
May 29, 2011, 07:52 AM
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

[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

[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



robbieduncan
May 29, 2011, 07:54 AM
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...

bradnet
May 29, 2011, 08:23 AM
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

robbieduncan
May 29, 2011, 08:27 AM
Then you'll have to set the size of the image view to the size of the image (in the code).

bradnet
May 29, 2011, 08:55 AM
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

robbieduncan
May 29, 2011, 09:45 AM
how would i reference the url to get the image height.

:confused: You wouldn't. You'd use the obvious method of UIImage.

bradnet
May 29, 2011, 03:03 PM
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
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