2013-10-21 52 views
1

當我在橫向上啓動視圖控制器時,單元格出現在錯誤的位置(從左側和右側放置的位置不正確),但在旋轉後,所有工作均可在縱向和橫向上均正常工作。 可以做些什麼呢?我試圖使佈局無效,調用旋轉方法無濟於事。UICollectionView橫向模式下的邊緣插入不正確

這裏是我的代碼:

設置流佈局:

的插圖
self.flowLayout = [[PSTCollectionViewFlowLayout alloc] init]; 
self.flowLayout.scrollDirection = PSTCollectionViewScrollDirectionVertical; 
self.flowLayout.minimumInteritemSpacing = VERTICAL_ITEM_SPACING; 
self.flowLayout.minimumLineSpacing = HORIZONTAL_ITEM_SPACING; 

方法:

- (UIEdgeInsets)collectionView:(PSTCollectionView *)collectionView 
         layout:(PSTCollectionViewLayout*)collectionViewLayout 
     insetForSectionAtIndex:(NSInteger)section { 

    self.currentOrientation = [UIApplication sharedApplication].statusBarOrientation; 

    self.insets = UIInterfaceOrientationIsPortrait(self.currentOrientation) ? UIEdgeInsetsMake(0, 72, 24, 72) : UIEdgeInsetsMake(0, 35, 24, 35); 

    //[self.collectionView.collectionViewLayout invalidateLayout]; 

    return self.insets; 
} 

回答

2

子類PSTCollectionViewFlowLayout

@interface FlowLayout : PSTCollectionViewFlowLayout 

集中的所有親裏面的FlowLayout

的初始化perty
-(id)init{ 
    self = [super init]; 
    if (self) { 
     self.scrollDirection = PSTCollectionViewScrollDirectionVertical; 
     self.minimumInteritemSpacing = VERTICAL_ITEM_SPACING; 
     self.minimumLineSpacing = HORIZONTAL_ITEM_SPACING; 

     self.currentOrientation = [UIApplication sharedApplication].statusBarOrientation; 
     self.sectionInset = UIInterfaceOrientationIsPortrait(self.currentOrientation) ? UIEdgeInsetsMake(0, 72, 24, 72) : UIEdgeInsetsMake(0, 35, 24, 35); 

    } 

    return self; 
} 

//初始化然後你的FlowLayout

self.flowLayout = [[FlowLayout alloc] init]; 

//重置的FlowLayout隨時隨地設備輪播

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{ 
    self.collectionView.collectionViewLayout = [[FlowLayout alloc] init]; 
} 
+0

這是唯一可行的方法。無論您使用'sectionInset'屬性還是'collectionView:layout:insetForSectionAtIndex:'委託方法,當您使佈局無效時,部分插頁都不會更新。我向Apple提交了一個[bug報告](http://openradar.appspot.com/radar?id=5255754231578624)。 – phatmann

0

我發現一個錯誤,我被測量的位置由單獨的頂視圖來看細胞的位置,這是錯誤的位置。細胞工作正常。

相關問題