我创建了一个抽屉视图。它包含一个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);
}
}
答案 0 :(得分:0)
[_ tableView setContentOffset:CGPointMake(0,-1)animated:YES]; [_tableView setContentOffset:CGPointMake(0,0)animated:YES]; 添加到函数adjustLayoutWithSearchBarTop将解决问题。 reasom可能是scrollview.isdragging在scrollViewDidEndDragging中保持为真。