zoukankan      html  css  js  c++  java
  • iOS开发——UIImageView

      1.图像点击之后,全屏浏览

    - (void)viewDidLoad {

      [super viewDidLoad];

      _myImage=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, klScreenWidth, klScreenHeight-270)];

        _myImage.userInteractionEnabled=YES;

        [self.scrollview addSubview:_myImage];

        

        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showZoomImageView:)];

        tapGesture.numberOfTapsRequired=1;

        [_myImage addGestureRecognizer:tapGesture];

    }

    -(void)showZoomImageView:(UITapGestureRecognizer *)tap

    {

        if (![(UIImageView *)tap.view image]) {

            return;

        }

        

        //scrollView作为背景

        UIScrollView *bgView = [[UIScrollView alloc] init];

        bgView.frame = [UIScreen mainScreen].bounds;

        bgView.backgroundColor = [UIColor blackColor];

        UITapGestureRecognizer *tapBg = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapBgView:)];

        [bgView addGestureRecognizer:tapBg];

        

        UIImageView *picView = (UIImageView *)tap.view;

        

        UIImageView *imageView = [[UIImageView alloc] init];

        imageView.image = picView.image;

        imageView.frame = [bgView convertRect:picView.frame fromView:self.view];

        [bgView addSubview:imageView];

        

        [[[UIApplication sharedApplication] keyWindow] addSubview:bgView];

        

        [UIView animateWithDuration:0.5 animations:^{

            CGRect frame = imageView.frame;

            frame.size.width = bgView.frame.size.width;

            frame.size.height = frame.size.width * (imageView.image.size.height / imageView.image.size.width);

            frame.origin.x = 0;

            frame.origin.y = (bgView.frame.size.height - frame.size.height) * 0.5;

            imageView.frame = frame;

        }];

    }

      2.图片的缩放

    @interface ViewController () <UIScrollViewDelegate>{

        UIScrollView *_scrollview;

        UIImageView *_imageview;

    }

    - (void)viewDidLoad {

        [super viewDidLoad];

        _scrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];

        _scrollview.delegate=self;

        //设置最大伸缩比例

        _scrollview.maximumZoomScale=5.0;

        //设置最小伸缩比例

        _scrollview.minimumZoomScale=1;

        [self.view addSubview:_scrollview];

        

        UIImage *image=[UIImage imageNamed:@"1"];

        _imageview=[[UIImageView alloc]initWithImage:image];

        _imageview.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);

        _imageview.userInteractionEnabled = YES;

        [_scrollview addSubview:_imageview];

    }

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

        return _imageview;

    }

  • 相关阅读:
    thinkphp在模型中自动完成session赋值
    highcharts实例教程二:结合php与mysql生成饼图
    程序员应该经常看看的网站
    highcharts实例教程一:结合php与mysql生成折线图
    2015-2-10 ecshop
    一个简单的javascript获取URL参数的代码
    table 西边框样式
    PHP 获取当前日期及格式化
    mysql 获取当前日期及格式化
    mysql时间int日期转换
  • 原文地址:https://www.cnblogs.com/yyt-hehe-yyt/p/5310171.html
Copyright © 2011-2022 走看看