iOS uses Uiscorllview to achieve two-finger zoom functions

Source: Internet
Author: User

The two-finger zoom function can be implemented not only with Uipinchgesturerecognizer gestures, but also with Uiscorllview, Uiscrollview can easily achieve the maximum and minimum zoom values, as well as the effect of scrolling. The code is as follows:


#import "ViewController.h" @interface Viewcontroller () @property (weak, nonatomic) Iboutlet Uiscrollview *scrollview;@ Property (Strong, Nonatomic) Uiimageview *imageview; @end @implementation viewcontroller-(void) viewdidload {    [ Super Viewdidload];        _scrollview.minimumzoomscale = 1.0;     Minimum scaling value    _scrollview.maximumzoomscale = 10.0;    Maximum zoom value    [_scrollview Setzoomscale:_scrollview.minimumzoomscale];    The initial zoom value    _scrollview.delegate = self;        _imageview = [[Uiimageview alloc] initwithimage:[uiimage imagenamed:@ "image"];    _imageview.frame = Self.view.frame;    [_scrollview Addsubview:_imageview];} #pragma mark-Returns the control that needs to be scaled-(UIView *) Viewforzoominginscrollview: (Uiscrollview *) ScrollView {    return _imageview;} -(void) didreceivememorywarning {    [Super didreceivememorywarning];} @end
The key point is to callViewforzoominginscrollview:Proxy method, which returns the control that needs to be scaled.


Demo's github address: Https://github.com/are1/UIScrollViewZoomScale

iOS uses Uiscorllview to achieve two-finger zoom functions

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.