2015-12-14 59 views
1

我用下面的代碼來創建UIRefreshControlUIRefreshControl顯示上述UICollectionViews細胞

_refreshControl = new UIRefreshControl(); 
_refreshControl.ValueChanged += RefreshTriggered; 
_collectionView.InsertSubview(_refreshControl, 0); 

而我沒有,爲什麼UIRefreshControl被繪製在UICollectionViewCell小號任何想法。

這裏是當我剛添加的刷新控制的UICollectionView的子視圖:

[0]: {<UIRefreshControl: 0x7c132fe0; frame = (0 0; 594 60); hidden = YES; autoresize = W; layer = <CALayer: 0x7c133250>>} 
[1]: {<UIImageView: 0x79f8a5d0; frame = (3 588.5; 588 2.5); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x79f89a70>> - (null)} 
[2]: {<UIImageView: 0x79fab7d0; frame = (588.5 584; 2.5 7); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x796171f0>> - (null)} 

這裏是當項目在UICollectionView加載的子視圖:

[0]: {<MovieCollectionViewCell: 0x796e7350; baseClass = UICollectionViewCell; frame = (0 0; 183 278.16); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x7c244bc0>>} 
[1]: {<MovieCollectionViewCell: 0x7c2b5850; baseClass = UICollectionViewCell; frame = (186 0; 183 278.16); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x7c2b5950>>} 
[2]: {<MovieCollectionViewCell: 0x7c2ba7d0; baseClass = UICollectionViewCell; frame = (0 281; 183 278.16); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x7c2ba8d0>>} 
[3]: {<MovieCollectionViewCell: 0x7c2bf440; baseClass = UICollectionViewCell; frame = (186 281; 183 278.16); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x7c2bf540>>} 
[4]: {<MovieCollectionViewCell: 0x7c2c42d0; baseClass = UICollectionViewCell; frame = (0 562.5; 183 278.16); clipsToBounds = YES; hidden = YES; opaque = NO; layer = <CALayer: 0x7c2c43d0>>} 
[5]: {<MovieCollectionViewCell: 0x7c2c9160; baseClass = UICollectionViewCell; frame = (186 562.5; 183 278.16); clipsToBounds = YES; hidden = YES; opaque = NO; layer = <CALayer: 0x7c2c9260>>} 
[6]: {<UIRefreshControl: 0x7c132fe0; frame = (0 -69.5; 369 60); autoresize = W; layer = <CALayer: 0x7c133250>>} 
[7]: {<UIImageView: 0x7c159e80; frame = (3 522; 363 2.5); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x7c159fb0>> - (null)} 
[8]: {<UIImageView: 0x7c15a480; frame = (363.5 -66.5; 2.5 224); opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x7c15a5b0>> - (null)} 

任何人的想法?

回答

5

嘗試發送refreshControll佈局過程後回這樣的:

- (void)viewDidLayoutSubviews 
{ 
    [super viewDidLayoutSubviews]; 

    [self.collectionView sendSubviewToBack:self.refreshControl]; 
} 

因爲UITableViewUICollectionView重用他們的細胞,他們奠定了其子視圖(可能通過自定義實現的一個非常具體的方式的layoutSubviews)。因此,插入自定義子視圖的位置在佈局過程後通常不會保留。這就是爲什麼你必須重寫viewDidLayoutSubviews並將視圖放回到你想要的位置。

UIRefreshControllUITableView自動檢測到並放回到其他子視圖的後面,但不是UICollectionView的情況,您必須手動執行此操作。對於任何其他自定義子視圖,您都必須爲UITableViewUICollectionView執行此操作。

+0

那麼這個工作,我打算把它標記爲已解決,但我想看看爲什麼發生這種情況的解釋。我認爲這是Xamarin或iOS中的一個錯誤。 – vrwim

+0

看我的編輯。只要我記得,事情一直在以這種方式工作,所以我不會把它稱爲一個錯誤,只是你需要知道的東西...... – deadbeef