iOS刷新控制高度

如何设置刷新控件的高度。 我正在使用http://www.jackrabbitmobile.com/design/ios-custom-pull-to-refresh-control/来创建用于刷新控制的自定义加载图标。 我想增加刷新控件的高度,即导航栏结束和tableview开始之间的空间,以便在图像下方和上方留出空间。 以下是我使用的代码:

- (void)setupRefreshControl { // Programmatically inserting a UIRefreshControl self.refreshControl = [[UIRefreshControl alloc] init]; // Setup the loading view, which will hold the moving graphics self.refreshLoadingView = [[UIView alloc] initWithFrame:self.refreshControl.bounds]; self.refreshLoadingView.backgroundColor = [UIColor clearColor]; // Setup the color view, which will display the rainbowed background self.refreshColorView = [[UIView alloc] initWithFrame:self.refreshControl.bounds]; self.refreshColorView.backgroundColor = [UIColor clearColor]; self.refreshColorView.alpha = 0.30; // Create the graphic image views self.compass_background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"compass_background.png"]]; self.compass_spinner = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"compass_spinner.png"]]; // Add the graphics to the loading view [self.refreshLoadingView addSubview:self.compass_background]; [self.refreshLoadingView addSubview:self.compass_spinner]; // Clip so the graphics don't stick out self.refreshLoadingView.clipsToBounds = YES; // Hide the original spinner icon self.refreshControl.tintColor = [UIColor clearColor]; // Add the loading and colors views to our refresh control [self.refreshControl addSubview:self.refreshColorView]; [self.refreshControl addSubview:self.refreshLoadingView]; // Initalize flags self.isRefreshIconsOverlap = NO; self.isRefreshAnimating = NO; // When activated, invoke our refresh function [self.refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged]; } 

我试过用

 self.refreshControl = [[UIRefreshControl alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)]; 

但这似乎不起作用。

来自UIRefreshControl类参考 :

拥有刷新控件的UITableViewController对象还负责设置该控件的框架矩形。 因此,您无需直接在视图层次结构中管理刷新控件的大小或位置。

您可以尝试一些乱码,如调配UITableViewController方法或添加布局约束,但它们可能不值得。

相反,我会使用像CBStoreHouseRefreshControl这样的自定义库来完成你想要的。

听起来你正在寻找刷新控件内的更多空间。 要以您提到的方式更改间距,您可以更改UI元素的坐标(罗盘+微调器,在我的示例中)或为图像添加填充。

scrollViewDidScroll方法是我设置UI坐标的地方。 当表被拉下时调用该方法,并且拉得越远,元素移动得越多。

JRTableViewController.m中的第55行和第56行是将更新的帧应用于元素(并且UI实际移动)的位置。 如果刷新控件中需要更多空间,则可以通过更改框架来更改元素的位置。

我希望能回答你的问题,如果没有,让我更多地了解你想要实现的效果。 希望我们的文章有所帮助! 让我们知道你创造了什么=)

–Anthony

UIRefreshControl自身的大小适合它的子视图。 因此,您需要更改其大小以使控件本身更改大小。

在您的UIRefreshControl子类中,您可以执行以下操作:

 override func layoutSubviews() { for view in subviews { view.frame = CGRectMake(1, 2, 3, 4) // or whatever size you want } super.layoutSubviews() } 

也许是一个黑客。 您可以删除所有视图并将其放置在agian中