【问题标题】:RFQuiltLayout and UICollectionView marginRFQuiltLayout 和 UICollectionView 边距
【发布时间】:2015-07-29 03:33:19
【问题描述】:

我正在尝试在我的集合视图中使用 RFQuiltLayout,但我一直遇到大小/边距问题。使用 4s 和 5s 模拟器似乎很好,但是当我在 6 或 6plus 上测试它时,块被推到屏幕的左侧并在右侧留下很大的空白。

不知道这里发生了什么。

image of problem

storyboard

这里是集合视图控制器的代码

.h

#import "RFQuiltLayout.h"
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UICollectionViewDataSource, UICollectionViewDelegate, RFQuiltLayoutDelegate, UICollectionViewDelegateFlowLayout>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (nonatomic, strong) NSArray *greekLetters;

.m

#import "ViewController.h"
#import "CollectionViewCell.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    RFQuiltLayout* layout = (id)[self.collectionView collectionViewLayout];
    layout.direction = UICollectionViewScrollDirectionVertical;
    layout.blockPixels = CGSizeMake(75, 75);
    
    
     self.greekLetters = @[@"Alpha", @"Beta", @"Cappa",@"Delta", @"Epsilon", @"Zeta", @"Eta", @"Theta", @"Iota", @"Kappa", @"Lambda", @"Mu", @"Nu", @"Xi", @"omicron", @"pi",@"rho",@"sigma", @"tau", @"upsilon", @"phi", @"chi",@"psi",@"omega"];
    
    

    
  //  [[self collectionView]setDataSource:self];
   // [[self collectionView]setDelegate:self];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma - mark CollectionView DelegateMethods:


-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{

    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    return self.greekLetters.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    NSString *CellIdentifer = @"cell";
    CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifer forIndexPath:indexPath];
    
    cell.cellLabel.text = [self.greekLetters objectAtIndex:indexPath.row];
    
    return cell;

}


#pragma mark – RFQuiltLayoutDelegate


-(CGSize) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout blockSizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row %2) {
        return CGSizeMake(2, 3);
        
    }else{
        return CGSizeMake(2, 2);
    }
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetsForItemAtIndexPath:(NSIndexPath *)indexPath {
    return UIEdgeInsetsMake(5, 5, 5, 5);
}

@end

不确定是什么原因造成的。 非常感谢任何帮助。

谢谢。

【问题讨论】:

    标签: ios objective-c uikit uicollectionview uicollectionviewlayout


    【解决方案1】:

    只玩块像素 对我来说,这些价值观完美运作

    layout.blockPixels = CGSizeMake(106.66, 106.66);
    

    【讨论】: