问题
I am trying to do a pinch to zoom with a uiscrollview that only has a backgroudnd image. First of all is this possible? Secondly can I do this with interface builder?
Basicly all I have atm is this
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
scrollView.backgroundColor = [UIColor blackColor];
scrollView.delegate = self;
scrollView.bounces = NO;
scrollView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"auckland-300.jpg"]];
UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"249a-134206f1d00-1342071f5d9.ImgPlayerAUCKLAND.png"]];
scrollView.contentSize = image.frame.size;
[scrollView addSubview:image];
scrollView.minimumZoomScale = scrollView.frame.size.width / image.frame.size.width;
scrollView.maximumZoomScale = 2.0;
[scrollView setZoomScale:scrollView.minimumZoomScale];
self.view = scrollView;
}
Any help would be appreciated
回答1:
You need to implement the UIScrollViewDelegate method.
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView;
and have it return a reference to your image view. This means you might want to manage a reference to the UIImageView stored within the scroll view.
Oh, and yes, it is doable in Interface Builder.
回答2:
Check out my demo application here:http://rexstjohn.com/facebook-like-ios-photo-modal-gallery-swipe-gestures/.
It demonstrates pinch to zoom of photos in a scrollview as well as a few other common functions you might want. Enjoy.
来源:https://stackoverflow.com/questions/8440586/pinch-to-zoom-using-uiscrollview