2015-02-06 107 views
0

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

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

尝试,但似乎并没有工作。

回答

-1

也许是黑客。您可以删除所有意见,并把它们agian

0

UIRefreshControl Class Reference

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

你可以尝试一些骇人听闻的方法或添加布局约束,但它们可能不值得。

相反,我会使用自定义库,如CBStoreHouseRefreshControl来实现你想要的。

0

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

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

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

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

--Anthony

1

UIRefreshControl尺寸本身,以适应它的子视图。所以你需要改变它们的尺寸来让控制本身改变尺寸。

在你UIRefreshControl子类,你可以这样做:

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

    super.layoutSubviews() 
}