Give a top inset to UIRefreshControl

孤者浪人 提交于 2019-12-30 08:02:20

问题


I use an UIRefreshControl like it (without an UITableViewController) :

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

Problem is the refresh wheel is positioned below the UINavigationController's translucent bar (ios7). There is only a few topic on this problem on StackOverflow. And they didn't bring any valuable solution to me.

What I wish is to make my UIRefreshControl's y position 80px down for example.

Note : I know it's not recommended to use UIRefreshControl outside an UITableViewController. So no need to warn about it.


回答1:


I found a solution, very simple, not so clean but works like a charm.

Just need to put the refresh control in another subview which is set down.

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];



回答2:


This is a version of AncAinu's answer in Swift 4.

let refreshView = UIView(frame: CGRect(x: 0, y: 80, width: 0, height: 0))
tableView.addSubview(refreshView)

refreshControl = UIRefreshControl()        
refreshControl.addTarget(self, action: #selector(self.viewDidBeginRefreshing), for: .valueChanged)        
refreshView.addSubview(refreshControl)



回答3:


Try to add this in the viewDidLoad in your UIViewController:

if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
    self.edgesForExtendedLayout = UIRectEdgeNone;


来源:https://stackoverflow.com/questions/19499182/give-a-top-inset-to-uirefreshcontrol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!