ios 图片由小到大和由大到小的渐进效果


- (void)testImageViewAnimal
{
    UIImage *_ljImage = [UIImage imageNamed:@"wuliu_banner"];
    _ljImageView = [[UIImageView alloc]init];
    _ljImageView.image = _ljImage;
    _ljImageView.frame = CGRectMake(kDEVICEWIDTH - 80, 100, 80, 80);
    _ljImageView.contentMode = UIViewContentModeScaleAspectFit;
    _ljImageView.userInteractionEnabled = YES;
    [self.view addSubview:_ljImageView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showView)];
    [_ljImageView addGestureRecognizer:tap];
}

CGRect origionFrame;
//图片放大效果----图片由小到大的渐进效果
- (void)showView
{
    //1.保存当前图片的原始图片的frame
    origionFrame = [_ljImageView convertRect:_ljImageView.bounds toView:self.view];
    
    //2.新建的图片用于放大用
    UIImage *_ljImage = [UIImage imageNamed:@"wuliu_banner"];
    UIImageView *_tfImageView = [[UIImageView alloc]init];
    _tfImageView.image = _ljImage;
    _tfImageView.frame = origionFrame;
    _tfImageView.tag = 1024;
    _tfImageView.contentMode = UIViewContentModeScaleAspectFit;//自动缩放
    _tfImageView.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hiddenview)];
    [_tfImageView addGestureRecognizer:tap];
    
    [[UIApplication sharedApplication].delegate.window.rootViewController.view addSubview:_tfImageView];
    [UIApplication sharedApplication].delegate.window.rootViewController.view.backgroundColor = [UIColor blackColor];
    //根据图片尺寸和将要放大后的宽度kDEVICEWIDTH(屏幕宽度),来计算图片的高度
    float height = _ljImage.size.height*kDEVICEWIDTH/_ljImage.size.width;
    
    //算出图片的相对中心坐标
    float y = (kDEVICEHEIGHT -  height)/2.0;
    self.view.alpha = 0;
    [UIView animateWithDuration:5 animations:^{
           //图片放大后的尺寸
           _tfImageView.frame = CGRectMake(0, y, kDEVICEWIDTH, height);
        //self.view.alpha = 1;
    } completion:^(BOOL finished) {
       
    }];
}

//图片缩小效果----图片由大到小的渐进效果
- (void)hiddenview
{
   [UIApplication sharedApplication].delegate.window.rootViewController.view.backgroundColor = [UIColor clearColor];
   UIImageView *_ljView = [[UIApplication sharedApplication].delegate.window.rootViewController.view viewWithTag:1024];
    
   CHDebugLog(@"before------%@",[NSDate date]);
   [UIView animateWithDuration:3 animations:^{
       _ljView.frame =origionFrame;
   } completion:^(BOOL finished) {
        CHDebugLog(@"before------%@",[NSDate date]);
        [_ljView removeFromSuperview];
        self.view.alpha = 1;
   }];
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值