Quote:
Originally Posted by starwarsdevwookie59
I have a scroll view that displays an image. The code below is in the viewdidload section. How in the world do i get it to zoom in? I've tried so many different tutorials and im lost. Anyone know how to zoom on this? Code would be great! Thanks so much!
[scrollView2 setBackgroundColor:[UIColor blackColor]];
[scrollView2 setCanCancelContentTouches:NO];
scrollView2.clipsToBounds = YES;
scrollView2.indicatorStyle = UIScrollViewIndicatorStyleWhite;
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image0.png"]];
[scrollView2 addSubview:imageView];
[scrollView2 setContentSize:CGSizeMake(imageView.frame.size.wid th, imageView.frame.size.height)];
[scrollView2 setScrollEnabled:YES];
[imageView release];
|
You need this scroll view delegate UIScrollViewDelegate
this is you .h file
Code:
IBOutlet UIScrollView *myScrollView;
UIImageView *myImage;
this is your .m file.
Code:
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.austinbull.com/clonemines.png"]]]];
[self setMyImage:tempImageView];
[tempImageView release];
myScrollView.contentSize = CGSizeMake(myImage.frame.size.width, myImage.frame.size.height);
myScrollView.maximumZoomScale = 4.0;
myScrollView.minimumZoomScale = 0.75;
myScrollView.clipsToBounds = YES;
myScrollView.delegate = self;
[myScrollView addSubview:myImage];
this is working for me.