如何把视图带到UIView层次结构的顶端



我的应用程序目前有一个搜索栏,并生成一个从搜索栏下拉结果的持有人视图。然而,ResultContainerView在我的其他视图后面。我想知道如何把那个搜索栏容器视图到UIView层次结构的顶部。我尝试使用[super bringSubviewToFront:_searchResultsHolderView]; ,但没有工作。这是我的方法,当搜索栏被点击。

- (void)_expandSearchResults
{
    CCLogVerbose (@"");
    _searchResultsHolderView.alpha = 0.0;
    _searchResultsHolderView.hidden = NO;
    [_searchResultsHolderView setFrameHeight:10];
    [UIView beginAnimations:@"expandSearchResults" context:nil];
    [UIView setAnimationDuration:kAnimationDuration_SearchResults];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector (searchAnimationDidStop:finished:context:)];
    _searchResultsHolderView.alpha = 1.0;
    [_searchResultsHolderView setFrameHeight:_searchResultsHt];
    [super bringSubviewToFront:_searchResultsHolderView];
    [UIView commitAnimations];  // start animation
}

这是我的reloadData方法

- (void)_reloadSearchResults:(NSString *)searchS
{
    CCLogVerbose (@"");
    if ([searchS length] == 0) {
        _searchResults = nil;
        [_searchResultsTableView reloadData];
        return;
    }
    NSAssert (self.patientService != nil, @"The Patient Service is invalid");
    [self.patientService searchPatients:searchS
        expandType:AllPatientExpansions
        success:^(NSArray *list) {
          _searchResults = list;
          [_searchResultsTableView reloadData];
        }
        failure:^(NSError *error) {
          CCLogDebug (@"Failed: %@", error);
        }];
}
[self.superview bringSubviewToFront:self];
    [self bringSubviewToFront:_searchResultsHolderView];

首先,您需要将self带到堆栈的顶部。之后,你可以呼叫bringSubViewToFront,并把你的_searchResultsHolderView带到前面。

最新更新