ScrollView for ipad Image scrolling and scaling through gestures

Source: Internet
Author: User

 

When previewing an image on an ipad, if we want to scale and scroll (similar to google maps), we need to use ScrollView

 

------- View Controller definition:

 

@ Interface TestBedViewController: UIViewController <UIScrollViewDelegate>

 

{

 

UIImage * weathermap;

 

}

 

@ Property (retain) UIImage * weathermap;

 

@ End

 

 

@ Implementation TestBedViewController

 

@ Synthesize weathermap;

 

// Specify the Image in all the scrollviews when using the zoom gesture.

 

-(UIView *) viewForZoomingInScrollView :( UIScrollView *) scrollView

 

{

 

Return [self. view viewwithtagag: 201];

 

}

 

 

/*

 

-(Void) scrollViewDidEndZooming :( UIScrollView *) scrollView withView :( UIView *) view atScale :( float) scale

 

{

 

}

 

*/

 

 

-(Void) viewDidLoad

 

{

 

 

// Create a scroll view and set the size and height of the proxy object px py width

 

UIScrollView * sv = [[UIScrollView alloc] initWithFrame: CGRectMake (0.0f, 0.0f, 3200000f, 284.0f)] autorelease];

 

Sv. contentSize = self. weathermap. size; // The UIImage object to be scaled.

 

Sv. delegate = self; // sets the proxy object

 

 

// Create an image object

 

UIImageView * iv = [[UIImageView alloc] initWithImage: self. weathermap] autorelease];

 

Iv. userInteractionEnabled = YES;

 

Iv. tag= 201;

 

 

// Calculate the zoom Value

 

Float minzoomx = sv. frame. size. width/self. weathermap. size. width;

 

Float minzoomy = sv. frame. size. height/self. weathermap. size. height;

 

Sv. minimumZoomScale = MIN (minzoomx, minzoomy); // the minimum scale to the current ScrollView

 

Sv. maximumZoomScale = 3.0f; // scale up to three times the image size.

 

 

// Add an image in scorllView

 

[Sv addSubview: iv];

 

[Self. view addSubview: sv];

 

}

 

@ End

 

Author sdhjob

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.