Scale an image using scrollview

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.