【问题标题】:How to bring View to top of UIView Hierarchy如何将视图带到 UIView 层次结构的顶部
【发布时间】:2026-02-09 15:30:01
【问题描述】:

我的应用目前有一个搜索栏,并生成从搜索栏下拉的结果的持有者视图。但是,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);
        }];
}

【问题讨论】:

    标签: objective-c uitableview uiview


    【解决方案1】:
    [self.superview bringSubviewToFront:self];
        [self bringSubviewToFront:_searchResultsHolderView];
    

    首先你需要把self 放到栈顶。之后,您可以拨打bringSubViewToFront 并将您的_searchResultsHolderView 带到前面。

    【讨论】:

      最近更新 更多