Scale an image using ScrollView
ViewController. h
@interface ViewController : UIViewController
{ UIScrollView *_scrollView;}
ViewController. m
# Import "ViewController. h "@ interface ViewController () @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; // create a rolling VIEW _ scrollView = [[UIScrollView alloc] initWithFrame: CGRectMake (0, 0,320,480)]; _ scrollView. delegate = self; // set the maximum method multiple _ scrollView. maximumZoomScale = 2; // you can specify the minimum shrinkage factor _ scrollView. minimumZoomScale =. 5; [self. view addSubview: _ scrollView]; UIImageView * imageView = [[UIImageView alloc] initWithFrame: CGRectMake (0, 0,320,480)]; imageView. tag = 101; imageView. userInteractionEnabled = YES; imageView. image = [UIImage imageNamed: @ "0.JPG"]; [_ scrollView addSubview: imageView]; // Add a gesture ** tap = [[UITapGestureRecognizer alloc] initWithTarget: self action: @ selector (tapAction)]; tap. numberOfTapsRequired = 2; [imageView addGestureRecognizer: tap];}-( Void) tapAction {[UIView beginAnimations: nil context: nil]; [UIView setAnimationDuration :. 5]; // _ scrollView. zoomScale = 2; // if (_ scrollView. zoomScale = 2) {// _ scrollView. zoomScale = 1; //} else {// _ scrollView. zoomScale = 2; //} _ scrollView. zoomScale = _ scrollView. zoomScale = 2?; [UIView commitAnimations];} # pragma mark-UIScrollView delegate // used to set the view to be zoomed in and out-(UIView *) viewForZoomingInScrollView :( UIScrollView *) scrollView {UIImageView * imageView = (UIImageView *) [self. view viewWithTag: 101]; return imageView;} // if the view is placed, call-(void) scrollViewDidZoom (UIScrollView *) in real time *) scrollView {// scale ratio CGFloat scale = scrollView. zoomScale; NSLog (@ "scaling in progress, scaling factor: % f", scale) ;}// scale to be started //-(void) scrollViewWillBeginZooming :( UIScrollView *) scrollView withView :( UIView *) view NS_AVAILABLE_IOS (3_2); // called before the scroll view begins zooming its content // end zooming //-(void) scrollViewDidEndZooming :( UIScrollView *) scrollView withView :( UIView *) view atScale :( CGFloat) scale; // scale between minimum and maximum. called after any 'bounce 'animations-(void) didReceiveMemoryWarning {[super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated .} @ end