【问题标题】:uitableview still show VerticalScrollIndicator when dragging finisheduitableview 在拖动完成时仍然显示 VerticalScrollIndicator
【发布时间】:2016-03-28 10:48:20
【问题描述】:

我创建了一个视图作为抽屉。它包含一个 UITableview。当我向下拖动 UITableview 时,视图将向下滑动,并且 UITableview 的 contentoffset.y 仍然为 0; 我在scrollViewDidScroll和scrollViewDidEndDragging中更改了UITableview框架,并且在动画后UITableview似乎仍在拖动,如果我单击UITableview不会导致单元格被选中但VerticalScrollIndicator隐藏,之后UITableview返回正常。

- (void)moveWithOffset:(CGFloat)offset {

CGFloat searchBarTop = _searchBar.top;
    self.height = SCREEN_HEIGHT-NavBar_HEIGHT;
    if (offset > 0) {
        if (GestureViewHeight - _searchBar.top > 0.1) {
            _gestureView.hidden = YES;
            searchBarTop = (_searchBar.top+offset) < GestureViewHeight ? (_searchBar.top+offset) : GestureViewHeight;
        } else {
            _gestureView.hidden = NO;
            if (self.top < SCREEN_HEIGHT/2) {
                self.top = (self.top+offset) < SCREEN_HEIGHT/2 ? (self.top+offset) : SCREEN_HEIGHT/2;
            }
        }
    } else if (offset < 0) {
        if (self.top - NavBar_HEIGHT > 0.1) {
            _gestureView.hidden = NO;
            self.top = (self.top+offset) > 64 ? (self.top+offset) : 64;
            searchBarTop = GestureViewHeight;
        } else {
            _gestureView.hidden = YES;
            if (searchBarTop > 0) {
                searchBarTop = (_searchBar.top+offset) > 0 ? (_searchBar.top+offset) : 0;
            }
        }
    }

[self adjustLayoutWithSearchBarTop:searchBarTop];

}

- (void)endMoving {
if ((int)self.top == NavBar_HEIGHT) {
    _state = ALDHotScenicSpotSearchViewStateUp;
} else if ((int)self.top == SCREEN_HEIGHT*2/3) {
    _state = ALDHotScenicSpotSearchViewStateMiddle;
} else if ((int)self.top == SCREEN_HEIGHT/2) {
    _state = ALDHotScenicSpotSearchViewStateDown;
} else {
    if (self.top < SCREEN_HEIGHT/3 && _state != ALDHotScenicSpotSearchViewStateUp) {
        _state = ALDHotScenicSpotSearchViewStateUp;
    } else if (self.top > SCREEN_HEIGHT/3 && _state != ALDHotScenicSpotSearchViewStateDown) {
        _state = ALDHotScenicSpotSearchViewStateDown;
    } else {
        _state = ALDHotScenicSpotSearchViewStateMiddle;
    }
}
[self animatingToState:_state];

}

- (void)animatingToState:(ALDHotScenicSpotSearchViewState)state {
switch (state) {
    case ALDHotScenicSpotSearchViewStateUp:
    {
        [UIView animateWithDuration:0.3 animations:^{
            self.frame = CGRectMake(0, NavBar_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT-NavBar_HEIGHT);
            _gestureView.hidden = YES;
            [self adjustLayoutWithSearchBarTop:0];
        }];
    }
        break;
    case ALDHotScenicSpotSearchViewStateDown:
    {
        [UIView animateWithDuration:0.3 animations:^{
            self.frame = CGRectMake(0, SCREEN_HEIGHT/2, SCREEN_WIDTH, SCREEN_HEIGHT/2);
            _gestureView.hidden = NO;
            [self adjustLayoutWithSearchBarTop:GestureViewHeight];
        }];
    }
        break;
    case ALDHotScenicSpotSearchViewStateMiddle:
    {
        [UIView animateWithDuration:0.3 animations:^{
            self.frame = CGRectMake(0, SCREEN_HEIGHT/3, SCREEN_WIDTH, SCREEN_HEIGHT*2/3);
            _gestureView.hidden = NO;
            [self adjustLayoutWithSearchBarTop:GestureViewHeight];
        }];
    }
        break;

    default:
        break;
}

}

- (void)adjustLayoutWithSearchBarTop:(CGFloat)top {
self.frame = CGRectMake(0, self.top, self.width, SCREEN_HEIGHT-self.top);
_searchBar.frame = CGRectMake(0, top, self.width, 44);
_tableView.frame = CGRectMake(0, _searchBar.bottom, self.width, self.height-_searchBar.bottom);

}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (_isSwiping) {
    _isSwiping = NO;
    [self endMoving];

}

}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView.contentOffset.y < 0 && !scrollView.isDecelerating && (int)_searchBar.top == 0) {
    _isSwiping = YES;
}
if (_isSwiping) {
    [self moveWithOffset:-scrollView.contentOffset.y];
    scrollView.contentOffset = CGPointMake(0, 0);
}

}

【问题讨论】:

  • 只有当我快速向下拖动 tableview 时才会发生这种情况,当缓慢向下拖动时它工作正常

标签: ios objective-c iphone uitableview


【解决方案1】:

[_tableView setContentOffset:CGPointMake(0, -1) 动画:YES]; [_tableView setContentOffset:CGPointMake(0, 0) 动画:YES]; 添加到函数 adjustLayoutWithSearchBarTop 将解决问题。原因可能是 scrollview.isdragging 在 scrollViewDidEndDragging 中保持真实。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多