Viewcontroller. h
@interface ViewController : UIViewController<UIScrollViewDelegate>{ 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
Scale an image using scrollview