如何设置刷新控件的高度。我正在使用http://www.jackrabbitmobile.com/design/ios-custom-pull-to-refresh-control/以创建用于刷新控件的自定义加载图标。我想增加刷新控件的高度,即导航栏结束和表视图开始之间的空间,以便在图像下方和上方都有空间。下面是我使用的代码:
- (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()
}
也许是黑客。您可以删除所有视图并将其放置在中