scrollview 圖片放大 捏合 瓦片地圖 相關注意事項,scrollview瓦片

來源:互聯網
上載者:User

scrollview 圖片放大 捏合 瓦片地圖 相關注意事項,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];}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.