Notes for scrollview Image zoom-in and Kneading tile maps, scrollview tiles

Source: Internet
Author: User

Notes for scrollview Image zoom-in and Kneading tile maps, scrollview tiles

The inaugural Wenbo company wants to write tile maps for the museum APP. Here we will summarize some problems encountered in the development process (which will be updated continuously and will also be the learning stage)

Anxious to write the project can directly look at code4 on the ready-made tile map code: http://www.code4app.com/ios/Tiled-Scroll-View/4fba3fd66803fa8413000000

1. First, use scrollview to scale the image: You need to set

MaximumZoomScale; // default is 1.0. must be> minimum zoom scale to enable zooming ***** the zoom effect can be achieved only when the value of this attribute is set to be greater than 1.0

The code below

//. H file # import <UIKit/UIKit. h> @ interface HDMapView: UIScrollView <UIScrollViewDelegate>-(instancetype) initWithFrame :( CGRect) frame andContentSize :( CGSize) contentSize;-(void) setMapImage :( UIImage *) image; @ end //. m file # import "HDMapView. h "@ interface HDMapView () @ property (strong, nonatomic) UIImageView * myImageView; @ end @ implementation HDMapView-(instancetype) initWithFrame :( CGRect) frame andContentSize :( CGSize) contentSize {self = [super initWithFrame: frame]; if (self) {self. maximumZoomScale = 17; self. frame = frame; self. delegate = self; self. contentSize = contentSize; self. myImageView = [[UIImageView alloc] initWithFrame: CGRectMake (0, 0, contentSize. width, contentSize. height)]; self. myImageView. userInteractionEnabled = YES; [self addSubview: self. myImageView]; UITapGestureRecognizer * twiceTap = [[UITapGestureRecognizer alloc] initWithTarget: self action: @ selector (tapTwice)]; twiceTap. numberOfTapsRequired = 2; twiceTap. numberOfTouchesRequired = 1; [self. myImageView addGestureRecognizer: twiceTap];} return self;}-(void) tapTwice {if (self. zoomScale> 3) {[self setZoomScale: 1.0 animated: YES];} else {CGFloat a = self. zoomScale; a ++; [self setZoomScale: a animated: YES] ;}}-(void) setMapImage :( UIImage *) image {self. myImageView. image = image ;}# pragma mark-UIScrollViewDelegate-(UIView *) viewForZoomingInScrollView :( UIScrollView *) scrollView {return self. myImageView;}-(void) scrollViewDidEndZooming :( UIScrollView *) scrollView withView :( UIView *) view atScale :( CGFloat) scale {[self setZoomScale: scale animated: YES];}

 

Related Article

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.