TableView 드롭다운 보기 확대 및 이미지 전시

3546 단어

다음은 애니메이션 효과입니다.


애니메이션.gif
말을 많이 하지 않고 바로 코드에 올리다
뷰 생성
    //UITableView   ImageView
    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, V_Width, V_height/3)];
    self.imageView.image = [UIImage imageNamed:@"3"];
    //  imageView     
    self.imageView.contentMode = UIViewContentModeScaleAspectFill;
    self.imageView.userInteractionEnabled = YES;
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(createAllImageView)];
    [self.imageView addGestureRecognizer:tap];
    
    //UITableView
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, V_Width, V_height) style:UITableViewStylePlain];
    //  tableView    
    self.tableView.contentInset = UIEdgeInsetsMake(V_height/3, 0, 0, 0);
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    [self.view addSubview:self.tableView];

    [self.view addSubview:self.imageView];

TableView 드래그 시 이벤트
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    CGPoint point = scrollView.contentOffset;
    //      
    if (point.y < -V_height/3 && point.y >= -V_height/3-60) {
        CGRect rect = self.imageView.frame;
        rect.origin.y = 0;
        rect.size.height = -point.y;
        self.imageView.frame = rect;
    }
    //        
    if (point.y > -V_height/3) {
        CGRect rect = self.imageView.frame;
        rect.origin.y = -point.y - V_height/3;
        self.imageView.frame = rect;
    }
    //       ,    View
    if (point.y <= -V_height/3-60) {
        [self createAllImageView];
    }
}

새 뷰 작성
/**
 *   Window     View
 */
- (void)createAllImageView{
    //V_Width        
    //V_height        
    
    //        _allView,     
    if (_allView) {
        return;
    }
    
    //Window  View
    _allView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, V_Width, V_height/3)];
    _allView.backgroundColor = [UIColor blackColor];
    
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeAllImageView:)];
    [_allView addGestureRecognizer:tap];
    
    //     ImageView
    _likeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, V_Width, V_height/3)];
    _likeImageView.image = [UIImage imageNamed:@"3"];
    [_allView addSubview:_likeImageView];
    
    // Window     
    [[UIApplication sharedApplication].keyWindow addSubview:_allView];
    
    CGRect rect1 = _allView.frame;
    rect1.size.height = V_height;
    
    CGRect rect2 = _likeImageView.frame;
    rect2.origin.y = (V_height - V_height/3)/2;
    
    //    
    [UIView animateWithDuration:0.8 animations:^{
        _allView.frame = rect1;
        _likeImageView.frame = rect2;
    }];
}

Window에서 보기 제거
/**
 *    Window  View
 *
*/
- (void)removeAllImageView:(UITapGestureRecognizer *)tap{
    
    CGRect rect1 = _allView.frame;
    rect1.size.height = V_height/3;
    
    CGRect rect2 = _likeImageView.frame;
    rect2.origin.y = 0;
    
    //    
    [UIView animateWithDuration:0.5 animations:^{
        _allView.frame = rect1;
        _likeImageView.frame = rect2;
        _allView.alpha = 0;
    } completion:^(BOOL finished) {
        [_likeImageView removeFromSuperview];
        [_allView removeFromSuperview];
        _allView = nil;
    }];
}


tableView의 일부 에이전트 이벤트는 여기에 상세하게 쓰여 있지 않습니다. 여러분의 지적을 환영합니다

좋은 웹페이지 즐겨찾기