Resize UICollectionView and its sub views in IOS - 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);
}

Related

UIcollection view showing the images stacked in a single view

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

Ipad UX creating news Board using UIcollectionView

I'm new on IOS development and I'm working on Ipad app for News Blog and I want to create Home screen look like this :
So my question is what's the best way to do that?
I mean, Should I create reusable view ( two views : one for the big size
post and the second for the small size post), then I add those view to my UIViewController in storyboard.
Or, create one reusable view with the big size and when I added it to storyboard I resize it (I'm not sure if this solution can be achieved and create UIview with dynamic size )?
Or, I create those view directly in my storyBoard and no need for using reusable component ?
Update
Thank's To Larme solution I've used UIcollectionView. But the problem I can't push the two first small row, in red circle, to top of screen and add under them two other small Cell
I want to have 4 small cells on the right big cell
This is my code:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
CGSize imgSize = CGSizeMake(230, 160);
if (indexPath.row == 0) {
//double the size for the first cell
imgSize = CGSizeMake(490, 360);
}
return imgSize;
}
-(UIEdgeInsets)collectionView:
(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsMake(5, 5, 5, 5);
}

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:

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 :)

Why there is a black gap between UICollectionView cells?

I want to display several cells in a UICollectionView in this manner: each cell is like a page to user, and an active UICollectionViewCell should occupy the full bound of the UICollectionView.
However for some reasons, there is black gap between cells after scrolling right.
Why does it happen?
I have already defined this function to control the size of "page" view:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
// the size is half of the screen
return CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height/2.0);
}
Looks like you need to set minSpacing to 0.
This sets the minimum gap between each item and also between the items and the edge of the collection view.

Resources