Reputation: 3948
I have setup a UICollectionView in interface builder with:
Frame is 320x180 Cell size is 320x180 Flow Layout cell size is 320x180 Insets are all at 0
Yet, somehow, when my iniWithFrame method is called, it's getting me a smaller height. 160! And not 180.
My custom Cell is also 320x180;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self = [[[NSBundle mainBundle] loadNibNamed:@"FSGalleryCell" owner:self options:nil] objectAtIndex:0];
}
return self;
}
Not only that, the UICollectionView Y origin is showing about 50 points lower than it is in interface builder.
I don't have any constraints set. I have tried to disable Auto Layout.
Also if I try to manually do this: cell contents don't show.
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(320, 180);
}
Only If I leave it like this:
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return self.collectionView.frame.size;
}
I'm expecting the last one to work because it's 320x160. Anything bigger and it won't show.
Everything is working fine in iOS7. It's iOS6 that these problems show up.
All help is greatly appreciated!!
Upvotes: 2
Views: 379
Reputation: 8029
You need to set the automaticallyAdjustsScrollViewInsets
and edgesForExtendedLayout
to match what you want to happen in your iOS 6.
If you want something the same as iOS 6 without anything going underneath the navigation bar and without automatically adjusting the insets then you can do something like the following in your UIViewController:
if ([self respondsToSelector:@selector(setAutomaticallyAdjustsScrollViewInsets:)]) {
self.automaticallyAdjustsScrollViewInsets = NO;
}
if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
self.edgesForExtendedLayout = UIExtendedEdgeLeft | UIExtendedEdgeBottom | UIExtendedEdgeRight;
}
Upvotes: 1
Reputation: 9363
That 20px is status bar. In iOS 7, the new status bar is introduced with 20px bigger in window size. (iOS 6/7 delta height)
You should not disable auto layout to deal with this delta height. Please refer to "Supporting Older Versions of iOS Alongside iOS 7" section in http://www.doubleencore.com/2013/09/developers-guide-to-the-ios-7-status-bar/ for more information.
and an example, Status bar and navigation bar issue in IOS7
Enjoy coding !
Upvotes: 1