IOS下拉放大图片

作者: zhaok | 来源:发表于2017-01-24 14:56 被阅读117次

    个人很喜欢这种效果,后面会在这个项目更新新效果。
    版本记录
    2017.1.24 (最基础图片下拉放大)
    https://github.com/zhaokera/downPhoto

    002.gif

    图片等比放大
    _img.contentMode = UIViewContentModeScaleAspectFill;

    - (UITableView *)tableView {
        _tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.contentInset = UIEdgeInsetsMake(imgH, 0, 0, 0);
        
        _img = [[UIImageView alloc] initWithFrame:CGRectMake(0, -imgH, [[UIScreen mainScreen] bounds].size.width, imgH)];
        [_img setImage:[UIImage imageNamed:@"test"]];
        _img.contentMode = UIViewContentModeScaleAspectFill;
        [_tableView addSubview:_img];
        
        return _tableView;
    }
    
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
        
        CGPoint point = scrollView.contentOffset;
        NSLog(@"pointX=%f,pointY=%f",point.x,point.y);
        if (point.y < -imgH) {
            CGRect rect = _img.frame;
            rect.origin.y = point.y;
            rect.size.height = -point.y;
            _img.frame = rect;
        }
    }
    

    相关文章

      网友评论

        本文标题:IOS下拉放大图片

        本文链接:https://www.haomeiwen.com/subject/nkbzbttx.html