Non*_*ain 6 iphone objective-c uitableview ios uirefreshcontrol
我创建了一个UITableView,我想在我的半透明黑色状态栏下面滚动.在我的XIB中,我只是将表格视图的y位置设置为-20,它看起来都很好.
现在,我刚刚添加了一个即时刷新的iOS6 UIRefreshControl,但是由于-20°位置,它会从状态栏后面拖动.我希望它能够"伸展"到状态栏而不是落后.
这是有道理的,为什么它搞乱了,但似乎没有任何差异改变它的框架和tableview的内容插入等不会有所作为.
文档建议一旦设置了refreshControl,UITableViewController将从此开始处理它的位置.
有任何想法吗?
你可以像这样子类化UIRefreshControl和实现layoutSubviews:
@implementation RefreshControl {
CGFloat topContentInset;
BOOL topContentInsetSaved;
}
- (void)layoutSubviews {
[super layoutSubviews];
// getting containing scrollView
UIScrollView *scrollView = (UIScrollView *)self.superview;
// saving present top contentInset, because it can be changed by refresh control
if (!topContentInsetSaved) {
topContentInset = scrollView.contentInset.top;
topContentInsetSaved = YES;
}
// saving own frame, that will be modified
CGRect newFrame = self.frame;
// if refresh control is fully or partially behind UINavigationBar
if (scrollView.contentOffset.y + topContentInset > -newFrame.size.height) {
// moving it with the rest of the content
newFrame.origin.y = -newFrame.size.height;
// if refresh control fully appeared
} else {
// keeping it at the same place
newFrame.origin.y = scrollView.contentOffset.y + topContentInset;
}
// applying new frame to the refresh control
self.frame = newFrame;
}
Run Code Online (Sandbox Code Playgroud)
它需要考虑tableView contentInset,但您可以将topContentInset变量更改为您需要的任何值,它将处理其余的值.
我希望代码有足够的文档来理解它是如何工作的.
UIRefreshControl始终位于您的UITableView. 如果您需要更改刷新控件的放置位置,请尝试更改 tableView 的 top contentInset。UIRefreshControl在确定其位置时会考虑到这一点。
| 归档时间: |
|
| 查看次数: |
6722 次 |
| 最近记录: |