zoukankan      html  css  js  c++  java
  • scrollview 图片放大 捏合 瓦片地图 相关注意事项

    就职文博公司要为博物馆做APP 涉及到瓦片地图的编写 在这里总结一些开发中遇到的问题 (将会不断更新 也是学习阶段)

    着急写项目的同学 可以直接看code4上现成的瓦片地图代码:http://www.code4app.com/ios/Tiled-Scroll-View/4fba3fd66803fa8413000000

    1. 首先实现利用scrollview实现图片的缩放: 需要设置

    maximumZoomScale;     // default is 1.0. must be > minimum zoom scale to enable zooming  *****只有设置了这个属性值大于1.0 才能实现缩放效果

    下面上代码

    //.h 文件
    #import <UIKit/UIKit.h>
    
    @interface HDMapView : UIScrollView <UIScrollViewDelegate>
    
    -(instancetype)initWithFrame:(CGRect)frame andContentSize:(CGSize)contentSize;
    
    -(void)setMapImage:(UIImage*)image;
    
    @end
    
    //.m 文件
    #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];
    }
  • 相关阅读:
    Mysql如何进行分组,并且让每一组的结果按照某个字段排序,并且获取每一组的第一个字段
    Mysql报错:Packet for query is too large (1121604 > 1048576).You can change this value on the server by setting the max_allowed_packet variable
    JavaScript判断对象有没有定义
    本地设置VirtualBox虚拟机
    Mysql关于时间排序的问题
    PHP实现页面静态化
    301重定向的两种实现方法
    判断浏览器类型
    javascript DOM事件总结
    装饰器模式
  • 原文地址:https://www.cnblogs.com/ceasar/p/5241289.html
Copyright © 2011-2022 走看看