Las celdas auto dimensionadas de UICollectionview no funcionan

Quiero usar celdas de tamaño propio en mi vista de colección. Mis células no utilizan layout automático:

He implementado los methods según lo requerido, pero aún no están cambiando el tamaño correctamente.

Adjunto está el código:

@interface Cell : UICollectionViewCell @end @implementation Cell -(CGSize)sizeThatFits:(CGSize)size { return CGSizeMake(320, 200); } // I have tried with and without this -(UICollectionViewLayoutAttributes *)prefernetworkingLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes { UICollectionViewLayoutAttributes *attributes = [super prefernetworkingLayoutAttributesFittingAttributes:layoutAttributes]; CGRect frame = attributes.frame; frame.size = CGSizeMake(320, 200); return attributes; } @end @interface ViewController () <UICollectionViewDataSource> @property (nonatomic,strong) UICollectionView *collectionView; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; self.collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout]; [self.view addSubview:self.collectionView]; self.collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; [self.collectionView registerClass:[Cell class] forCellWithReuseIdentifier:@"cell"]; self.collectionView.dataSource = self; layout.estimatedItemSize = CGSizeMake(320, 10); // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - #pragma mark UICollectionViewDataSource - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return 10; } // The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath: - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath]; cell.contentView.backgroundColor = [UIColor networkingColor]; return cell; } 

Además, al girar el dispositivo me da un crash:

 *** Assertion failure in -[_UIFlowLayoutSection computeLayoutInRect:forSection:invalidating:], /SourceCache/UIKit_Sim/UIKit-3318.16.14/UIFlowLayoutSupport.m:763 2015-03-08 11:09:06.430 TestSelfSizingCells[77344:3177236] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UICollectionViewFlowLayout internal error' *** First throw call stack: ( 0 CoreFoundation 0x000000010881bf35 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x00000001084b4bb7 objc_exception_throw + 45 2 CoreFoundation 0x000000010881bd9a +[NSException raise:format:arguments:] + 106 3 Foundation 0x00000001080d15df -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195 4 UIKit 0x0000000109298e53 -[_UIFlowLayoutSection computeLayoutInRect:forSection:invalidating:] + 9052 5 UIKit 0x000000010925f96c __56-[UICollectionViewFlowLayout _updateItemsLayoutForRect:]_block_invoke + 509 6 CoreFoundation 0x0000000108754042 __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 114 7 CoreFoundation 0x000000010875379c -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 300 8 UIKit 0x000000010925f69c -[UICollectionViewFlowLayout _updateItemsLayoutForRect:] + 780 9 UIKit 0x000000010925fce2 -[UICollectionViewFlowLayout _fetchItemsInfoForRect:] + 583 10 UIKit 0x000000010925cde6 -[UICollectionViewFlowLayout _layoutAttributesForItemsInRect:] + 646 11 UIKit 0x000000010925e268 -[UICollectionViewFlowLayout layoutAttributesForElementsInRect:] + 119 12 UIKit 0x0000000109274130 __45-[UICollectionViewData validateLayoutInRect:]_block_invoke + 144 13 UIKit 0x0000000109273627 -[UICollectionViewData validateLayoutInRect:] + 1396 14 UIKit 0x000000010923b7b8 -[UICollectionView layoutSubviews] + 170 15 UIKit 0x0000000108c81973 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 521 16 QuartzCore 0x000000010c4f6de8 -[CALayer layoutSublayers] + 150 17 QuartzCore 0x000000010c4eba0e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380 18 QuartzCore 0x000000010c4f6d1d -[CALayer layoutIfNeeded] + 162 19 UIKit 0x0000000108d4374a -[UIViewController window:willAnimateRotationToInterfaceOrientation:duration:newSize:] + 211 20 UIKit 0x0000000108d47e84 __95-[UIViewController(AdaptiveSizing) _window:viewWillTransitionToSize:withTransitionCoordinator:]_block_invoke2889 + 73 21 UIKit 0x0000000109361a0e -[_UIViewControllerTransitionCoordinator _applyBlocks:releaseBlocks:] + 217 22 UIKit 0x000000010935ef2e -[_UIViewControllerTransitionContext __runAlongsideAnimations] + 139 23 UIKit 0x00000001090964d4 __58-[_UIWindowRotationAnimationController animateTransition:]_block_invoke + 96 24 UIKit 0x0000000108c7a362 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 473 25 UIKit 0x0000000108c7a5b7 +[UIView(UIViewAnimationWithBlocks) animateWithDuration:delay:options:animations:completion:] + 57 26 UIKit 0x0000000109096430 -[_UIWindowRotationAnimationController animateTransition:] + 408 27 UIKit 0x0000000108c52704 -[UIWindow _rotateToBounds:withAnimator:transitionContext:] + 761 28 UIKit 0x0000000108c54ac0 -[UIWindow _rotateWindowToOrientation:updateStatusBar:duration:skipCallbacks:] + 2134 29 UIKit 0x0000000108c55092 -[UIWindow _setRotatableClient:toOrientation:applyTransformToWindow:updateStatusBar:duration:force:isRotating:] + 559 30 UIKit 0x0000000108c541ee -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 116 31 UIKit 0x0000000108c54174 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 36 32 UIKit 0x0000000108c54021 -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 122 33 UIKit 0x0000000108c53100 __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke + 98 34 UIKit 0x0000000108c53079 -[UIWindow _updateToInterfaceOrientation:duration:force:] + 386 35 UIKit 0x0000000108c53450 -[UIWindow _updateInterfaceOrientationFromDeviceOrientation:] + 316 36 CoreFoundation 0x00000001087ebcec __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12 37 CoreFoundation 0x00000001086eb8a4 _CFXNotificationPost + 2484 38 Foundation 0x00000001080126b8 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66 39 UIKit 0x0000000108e70efc -[UIDevice setOrientation:animated:] + 282 40 UIKit 0x0000000108c1c476 -[UIApplication handleEvent:withNewEvent:] + 1474 41 UIKit 0x0000000108c1c90a -[UIApplication sendEvent:] + 79 42 UIKit 0x0000000108c086af _UIApplicationHandleEvent + 593 43 GraphicsServices 0x000000010bdec33e _PurpleEventCallback + 756 44 GraphicsServices 0x000000010bdebe26 PurpleEventCallback + 35 45 CoreFoundation 0x00000001087517c9 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 41 46 CoreFoundation 0x000000010875173b __CFRunLoopDoSource1 + 475 47 CoreFoundation 0x0000000108746f88 __CFRunLoopRun + 2200 48 CoreFoundation 0x0000000108746486 CFRunLoopRunSpecific + 470 49 GraphicsServices 0x000000010bdea9f0 GSEventRunModal + 161 50 UIKit 0x0000000108c08420 UIApplicationMain + 1282 51 TestSelfSizingCells 0x0000000107f87853 main + 115 52 libdyld.dylib 0x000000010adab145 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb) 

También he notado que cuando se usan diferentes tamaños de pantalla los resultados son muy importantes. Por ejemplo, en el iPhone 5, las células se ven "bien" al principio. Pero después de un time son jodidos.

También en el simulador de iPhone 6, la vista de colección no se desplaza en absoluto, hasta que gire el dispositivo hacia adelante y hacia atrás y, finalmente, la aplicación se bloquea.

introduzca la descripción de la imagen aquí