2015-02-06 106 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() 
}