图片点击放大效果

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
for(int i = 0; i < 2; i++)
{
    for(int j = 0; j < 2; j++)
    {
        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(j * 120 + 100, i * 150 + 200, 120, 150)];
        imgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",j+1+i+i]];

        imgView.tag = 100 + j+i+i;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(large:)];
        imgView.userInteractionEnabled = YES;

        [imgView addGestureRecognizer:tap];
        [self.view addSubview:imgView];
    }
}
}

- (void)large:(UITapGestureRecognizer *)tap
{
//获取四张图片交互都关掉
for(int i = 0; i < 4; i++)
{
    UIImageView *imgView = (UIImageView *)[self.view viewWithTag:100+i];
    imgView.userInteractionEnabled = NO;
}

//打开被点击的图片的交互
tap.view.userInteractionEnabled = YES;

//判断是否放大
if (_isLarge == NO) {
    //放大前记录视图原先的frame
    _frame = tap.view.frame;
    [UIView animateWithDuration:1.0 animations:^{
        //把点击的图片放到父视图的最上层
        [self.view bringSubviewToFront:tap.view];
        tap.view.frame = self.view.bounds;
    } completion:nil];
}else
{
    [UIView animateWithDuration:1.0 animations:^{
        tap.view.frame = _frame;
    } completion:^(BOOL finished) {
        //在图片缩小完成的时候打开所有图片的交互
        for(int i = 0; i < 4; i++)
        {
            UIImageView *imgView = (UIImageView *)[self.view viewWithTag:100+i];
            imgView.userInteractionEnabled = YES;
        }
    }];
}
_isLarge = !_isLarge;
}
分级目录: │ demo.html │ demo2.html │ demo3.html │ demo4.html │ demo5.html │ ├─css_pirobox │ │ css.css │ │ │ ├─demo1 │ │ ajax-loader.gif │ │ b_c.png │ │ b_l.png │ │ b_r.png │ │ close_btn.png │ │ close_btn_h.png │ │ c_l.png │ │ c_r.png │ │ link_out.png │ │ link_out_h.png │ │ next.png │ │ next_h.png │ │ pause.png │ │ pause_h.png │ │ play.png │ │ play_h.png │ │ prev.png │ │ prev_h.png │ │ style.css │ │ t_c.png │ │ t_l.png │ │ t_r.png │ │ │ ├─demo2 │ │ ajax-loader.gif │ │ b_c.png │ │ b_l.png │ │ b_r.png │ │ close_btn.png │ │ close_btn_h.png │ │ c_l.png │ │ c_r.png │ │ link_out.png │ │ link_out_h.png │ │ next.png │ │ next_h.png │ │ pause.png │ │ pause_h.png │ │ play.png │ │ play_h.png │ │ prev.png │ │ prev_h.png │ │ style.css │ │ t_c.png │ │ t_l.png │ │ t_r.png │ │ │ ├─demo3 │ │ ajax-loader.gif │ │ b_c.png │ │ b_l.png │ │ b_r.png │ │ close_btn.png │ │ close_btn_h.png │ │ c_l.png │ │ c_r.png │ │ link_out.png │ │ link_out_h.png │ │ next.png │ │ next_h.png │ │ pause.png │ │ pause_h.png │ │ play.png │ │ play_h.png │ │ prev.png │ │ prev_h.png │ │ style.css │ │ t_c.png │ │ t_l.png │ │ t_r.png │ │ │ ├─demo4 │ │ ajax-loader.gif │ │ b_c.png │ │ b_l.png │ │ b_r.png │ │ close_btn.png │ │ close_btn_h.png │ │ c_l.png │ │ c_r.png │ │ link_out.png │ │ link_out_h.png │ │ next.png │ │ next_h.png │ │ pause.png │ │ pause_h.png │ │ play.png │ │ play_h.png │ │ prev.png │ │ prev_h.png │ │ style.css │ │ t_c.png │ │ t_l.png │ │ t_r.png │ │ │ └─demo5 │ ajax
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值