ios - 更改 iOS App 中 UIRefreshControl 指示器的初始位置

标签 ios uitableview uirefreshcontrol

我正在使用 UITableView 和 UIRefreshControl 开发 iOS 应用。

我想将 UIRefreshControl 指示器的初始位置从默认值向下更改 50 像素。我写下以下代码。

但是,初始位置没有改变。它保持在原来的位置。

你能告诉我如何解决这个问题吗?

CGFloat customRefreshControlHeight = 50.0f;
CGFloat customRefreshControlWidth = 320.0f;
CGRect customRefreshControlFrame = CGRectMake(0.0f,
                                              customRefreshControlHeight,
                                              customRefreshControlWidth,
                                              customRefreshControlHeight);
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] initWithFrame:customRefreshControlFrame];
refreshControl.tintColor = [UIColor blackColor];
[refreshControl addTarget:self action:@selector(onRefresh:) forControlEvents:UIControlEventValueChanged];
[self.tableView addSubview:refreshControl];

最佳答案

直接设置框架是行不通的,但您仍然可以使用 AutoLayout 随时放置您的 refreshControl。只是不要忘记将 translatesAutoresizingMaskIntoConstraints 设置为 false

例如,这段代码将refreshControl设置在屏幕中间。

let refreshControl = UIRefreshControl()
collectionView.refreshControl = refreshControl
refreshControl.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint(item: refreshControl, attribute: .centerX, relatedBy: .equal, toItem: view, attribute: .centerX, multiplier: 1.0, constant: 0).isActive = true
NSLayoutConstraint(item: refreshControl, attribute: .centerY, relatedBy: .equal, toItem: view, attribute: .centerY, multiplier: 1.0, constant: 0).isActive = true

关于ios - 更改 iOS App 中 UIRefreshControl 指示器的初始位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25673380/

相关文章:

ios - UIPopoverController 顶部的 UITableViewController 不可见

iphone - UITableView 如何一次显示两个不同的数组?

iphone - UITableViewCellAccessoryCheckmark的逻辑

ios - 如何将 "pull to refresh"添加到 tableView,而不是 UITableViewController?

uitableview - Swift:不正确地使用 UIRefreshControl - 无法识别的选择器

iphone - 为什么作者在下面的代码段中没有对childController做release呢?

ios - 为什么我的应用程序在为 ui 元素分配弱引用时崩溃?

ios - 使用 UIRefreshControl 并设置 contentInset 时表格 View 内容跳转

ios - 保存未知数量的 NSArray

ios - 使用未解析的标识符 "Kanna",swift