给UIRefreshControl一个顶部插图

Anc*_*inu 13 uinavigationcontroller ios uirefreshcontrol ios7

我喜欢它使用UIRefreshControl(没有UITableViewController):

UIRefreshControl *refreshControl = [UIRefreshControl new];
[refreshControl addTarget:self action:@selector(viewDidBeginRefreshing:) forControlEvents:UIControlEventValueChanged];
[self.table addSubview:refreshControl];
Run Code Online (Sandbox Code Playgroud)

问题是刷新轮位于UINavigationController的半透明条(ios7)下方.StackOverflow上只有几个关于此问题的主题.他们没有为我带来任何有价值的解决方案.

我希望的是让我的UIRefreshControl的y位置降低80px.

注意:我知道不建议在UITableViewController外部使用UIRefreshControl.所以不需要警告它.

Anc*_*inu 30

我找到了一个解决方案,非常简单,不那么干净,但却像魅力一样.

只需要将刷新控件放在另一个设置的子视图中.

UIView *refreshView = [[UIView alloc] initWithFrame:CGRectMake(0, 80, 0, 0)];
[self.table addSubview:refreshView];

UIRefreshControl *refreshControl = [UIRefreshControl new];
[refreshControl addTarget:self action:@selector(viewDidBeginRefreshing:) forControlEvents:UIControlEventValueChanged];
[refreshView addSubview:refreshControl];
Run Code Online (Sandbox Code Playgroud)

  • 如上所示,在将`UIRefreshControl`作为子视图添加到容器`UIView`之前,确保将容器`UIView`添加到`UITableView`.我做了反之亦然,它失败了. (2认同)