UIcollection view showing the images stacked in a single view - ios

One of my storyboard has a table view cell which calls the collection view defined in the separate scene. Collection view includes a UIImage view with a page control till ios 10 each of the images used to display fully within the imageview after the upgrade all the images are showing up as stacked on one another as in the attached image.once i click on this stacked image everything becomes proper until i revisit the storyboard. Is there anything which changed with respect to UIImage or collectionview in the new upgrade?
The same code works fine in ipod.
Code Sample:
#pragma mark - UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return collectionView.bounds.size;
}
Is it something to do with pagecontrol being used??

I hope you would have used sizeForItemAtIndexPath for specifying collection view cell size previously and would have added UICollectionViewDataSource, UICollectionViewDelegate delegate methods.
Now for iOS 10 we need to add UICollectionViewDelegateFlowLayout delegate, only then sizeForItemAtIndexPath will be executed.
Try it I hope it will fix your issue.

Try explicitly providing the height and width of collectionView.bounds.size

Related

UICollectionView Different cells widths

Hi, I would like to make a design like this, I have a collectionView that has different sections, the first one has to be different... how can I do?
I have made different types of cells but it always has the same width as specified in the storyboard... Is there any way to set the width of the cell?
Thank you very much.
You have to use UICollectionViewDelegateFlowLayout, specifically this method:
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath
Just return there the size you want at the section or indexPath you need.
You will need to adopt the UICollectionViewDelegateFlowLayout protocol and implement the collectionView(_:layout:sizeForItemAtIndexPath:) method. This method is implemented to specify the size of individual items to the UICollectionViewFlowLayout object that does the layout in a collection view by default.
Here is a link to the relevant documentation.

Different Cell size in a collection view in ios

i already display the image as grid view using UICollectionView with equal size like follows
Next step i want to display cell as different size but the images fit into the that cell like this
this need to be work in the storyboard because other functions done in the storyboard so somebody help me..
In your collection view controller add:
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout*)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
//return the size of the cell based on image size or other criteria
}
Add constraints to the image:

Resize UICollectionView and its sub views in IOS

I am developing an IOS in which i am required to show the images in GridView. For this have used UICollectionView and images are also getting displayed in Grid.
I have used SWRevealViewController to implement Sidebar Navigation.
What i want to do is that when the SideBar is opened UICollectionView and its Cells to resize as shown in the image.
What i have already done is
The above images are from the same app built in Android.
Below are the images what i have done for IOS App.
If anybody can help to acheive the same would be a great help.
Thanks in advance.
when you are tapping the button call this
[self.collectionView performBatchUpdates:nil completion:nil];
it will will invalidate the layout and resize the cells with animation (you can just pass nil to both block params if you've no extra adjustments to perform).
and then
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
// Adjust cell size for the mode slider opened or closed
if (isSliderOpened) {
return CGSizeMake(100.f, 100.f);
}
return CGSizeMake(200.f, 200.f);
}

UICollectionView can't collapse or remove supplementary view

I have a uicollectionview using flow layout that has a supplementary header view which is a view that I only sometimes want to display. So basically I want to have a button that will, when clicked, remove the supplementary view from the collection view and also re-place all the items in the collection view with the consideration that the header is gone. Is this possible? I've tried it repeatedly in many ways. Changing the reference header size, changing my answer to the delegate method for the header size, invalidating the layout, reloading the data etc etc etc. What am I missing?
I just ran a test. I think that it's related to using UIDynamics, what is it in UIDynamics that would override my delegate response for header section reference size?
In your delegate's layout methods return the appropriate size for whatever state you're interested in:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
if (self.headerVisble) {
return CGSizeMake(collectionView.bounds.size.width, 30.0f);
}
else {
return CGSizeZero;
}
}
Then when you need to update the layout call:
[collectionView.collectionViewLayout invalidateLayout];
The collection view will ask the Layout object for new info which will in turn ask your delegate. I believe it will animate the change too.

UICollectionViewCell and Autolayout scaling

I've built a vanilla UICollectionView that uses cells that are the full size of my screen...
The ViewCells I am using are defined in IB with dimensions of 320x568, and I have added auto layout constraints that should allow these to scale down when the window size changes.
Is there a way to have a normal collection view flow layout detect changes in the available window (in-call bar, 3.5 inch screen, etc.), and update the viewcell default sizes so that they match the available real estate, or is this going to require customized code to listen for the change in resolution? If so, what is the method I need to implement to capture this change in window size?
This might work :
Subclass a UICollectionViewFlowLayout and override the method (shouldInvalidateLayoutForBoundsChange) like this :
- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
{
[self invalidateLayout];
return YES;
}
This will force a refresh of the layout on bounds changes of the collectionView. (a rotation for example).
also you'll have to implement the following method of UICollectionViewDelegate :
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return self.collectionView.bounds.size;
}
Now if you have good constraints on you collectionsView, it's frame should be updated on window changes and result in a layout update.
Let me know if it works :)

Resources