中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

iOS圖片縮小放大scollView實(shí)現(xiàn)代碼

2018-07-20    來源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬Linux鏡像隨意使用

使用ios SDK自帶的 UIScrollView 可以實(shí)現(xiàn)對(duì)圖片的縮放

現(xiàn)在給大家分享我的項(xiàng)目中可以直接使用的組件,需要引入 afnetworking等第三方框架

關(guān)于AFNetworking大家可以自行百度,使用它的目的是下載網(wǎng)絡(luò)圖片(使用SDWebImage也可以)

使用scrollView實(shí)現(xiàn)圖片的縮放,下面是一個(gè)可以直接使用的組件:

主要功能有:

顯示網(wǎng)絡(luò)圖片,捏合放大或者縮小,單擊關(guān)閉當(dāng)前圖片頁(yè)面,雙擊放大

    //  ImageDetailCon.h  
    //  
    //  
      
    #import <UIKit/UIKit.h>  
    @interface ImageDetailCon : UIViewController<UIScrollViewDelegate>    //需要使用 對(duì)應(yīng)的 協(xié)議  
    @property(strong,nonatomic)NSURL *imageURL;//給外界的接口,外界傳值給ImageDetailCon  *vc;,然后present出來即可  
    @end  
    //  
    //  ImageDetailCon.m  
    //  
      
    #import "ImageDetailCon.h"  
    #import <UIImageView+AFNetworking.h>//使用afnetworking框架  
    @interface ImageDetailCon ()  
    {  
        UIScrollView *scrollView;  
        UIImageView *imageView;  
    }  
    @end  
      
    @implementation ImageDetailCon  
    - (void)viewDidLoad  
    {  
        [super viewDidLoad];  
        scrollView=[[UIScrollView alloc]initWithFrame:self.view.bounds];  
        scrollView.maximumZoomScale=5.0;//圖片的放大倍數(shù)  
        scrollView.minimumZoomScale=1.0;//圖片的最小倍率  
        scrollView.contentSize=CGSizeMake(self.view.bounds.size.width*1.5, self.view.bounds.size.height*1.5);  
        scrollView.delegate=self;  
        imageView=[[UIImageView alloc]initWithFrame:self.view.bounds];  
        [imageView setImageWithURL:self.imageURL placeholderImage:[UIImage imageNamed:@"Fav_Img_Download"]];  
        [scrollView addSubview:imageView];  
        [self.view addSubview:scrollView];  
        imageView.userInteractionEnabled=YES;//注意:imageView默認(rèn)是不可以交互,在這里設(shè)置為可以交互  
        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapImage:)];  
        tap.numberOfTapsRequired=1;//單擊  
        tap.numberOfTouchesRequired=1;//單點(diǎn)觸碰  
        [imageView addGestureRecognizer:tap];  
        UITapGestureRecognizer *doubleTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doubleTap:)];  
        doubleTap.numberOfTapsRequired=2;//避免單擊與雙擊沖突  
        [tap requireGestureRecognizerToFail:doubleTap];  
        [imageView addGestureRecognizer:doubleTap];  
        imageView.contentMode=UIViewContentModeScaleAspectFit;  
          
    }  
    -(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView  //委托方法,必須設(shè)置  delegate  
    {  
        return imageView;//要放大的視圖  
    }  
      
    -(void)doubleTap:(id)sender  
    {  
        scrollView.zoomScale=2.0;//雙擊放大到兩倍  
    }  
    - (IBAction)tapImage:(id)sender  
    {  
        [self dismissViewControllerAnimated:YES completion:nil];//單擊圖像,關(guān)閉圖片詳情(當(dāng)前圖片頁(yè)面)  
    }  
    @end  

標(biāo)簽: 網(wǎng)絡(luò)

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:單例模式PHP實(shí)現(xiàn)代碼

下一篇: php版的24點(diǎn)游戲源碼