I've created a UICollectionView with an image in each cell. I'm wondering how I can make a trigger action which will make the image fullscreen like in facebook, intagram or other apps. What is the best way in Swift to achieve this?
the simplest solution in your case would be to put some code in
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
}
in this function you already have selected indexPath.row so it should be easy to access the right image in your datasource. for example, if you are using array of images imagesArray, the right image would be imagesArray[indexPath.row].
after that you can create new UIViewController with UIImageView to show this image, or just UIImageView that will be shown over this collection view.
(I think you should also add UICollectionViewDelegate and UICollectionViewDatasource to your current controller for this to work).
The simple solution is that you can add an gesture detection on the image view inside the collection view.
Related
I am trying to animate the first apparition of a cell in a collection view as simple as a ZoomOut + Fade IN of the cells when the collection view is first called.
I have NOT subclassed UICollectionViewFlowLayout so far as I did not think it was necessary for such small action and I do not need to further invalidate the layouts once the cells are displayed. There is actually no animations of the cell beyond their first apparition. Reading the apple's developper guidelines on the subject seems to confirm I should not go to the subclass route but still I have not found how to perform the animation I want.
I have played along the lines of defining the cells using UICollectionViewDelegateFlowLayout methods then performing a CGAffineTransform sequence in collectionView(_ collectionView: willDisplay cell: forItemAt indexPath: IndexPath) of UICollectionViewDelegate and the proper transformation does occur. Then I was thinking of reversing this transformation by calling a simple CGAffineTransform.Identity() in an animation but I have not found yet where (in which of the CollectionView classes method) to place it.
Thank you in advance for your king help!
I created collectionView as below:
I would like to create a collection view as same as this layout, with one biggest header cell like the one with red iPhone7. Now I wonder which approach is better, to create an extra cell or handle this in UICollectionViewFlowLayout?. My data is an array which fetched from JSON, so i would like to make the big cell is the first item.
Honestly, I see that second approach is quite complicated.
So can anyone help me to find best solution for this.
Thank you so much for reading this and have a nice day ahead.
Go to attribute inspector of UIColectionView.
From Accessories select Section Header
Once header view is visible , add your views to it.
Then in following method tweak accordingly:
override func collectionView(_ collectionView: UICollectionView ,viewForSupplementaryElementOfKind kind: String,at indexPath: IndexPath) -> UICollectionReusableView {
if kind == UICollectionElementKindSectionHeader{
return headerView
}
}
I searched the web for hours but I can't find a solution to my problem.
I have a View in my storyboard that contains a UICollectionView. I've set the cells of the UICollectionView to be really big (only one can appear on the screen, you have to swipe horizontally to see the others). In my application, I use this layout to ask the user some questions, one after another. The user can respond to those questions by touching buttons, move around a map, select a date, etc... Each questions have the same layout; they are displayed in a box, with a title label and a button. That's why I chose to use a UICollection View.
I want to display a specific view (the options that allows the user to answer (buttons, Map, DatePicker, etc..)) for each questions in the blue rectangle (see picture below).
A screenshot of my view
My idea was to create multiple ViewControllers in my StoryBoard and be able to tell : "ok, for the first question (first cell), put the view XXX in the container, for the second, put the view YYY, etc...".
How can I do this ?
I've tried to add a ContainerView but we can only link one view in the storyboard.
I want to able to do something like this :
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! SearchQuestionBox
cell.questionAnswersZone.view = storyboard.viewNumberOne //Just for the idea haha
return cell
}
I would suggest not using multiple view controllers.
Instead you could just add the views for each cell to the one main view controller. Keep in mind you can set a views frame to be offscreen.
I am still fairly new to programming and I do not quite understand UICollectionViews. Can a programmer add buttons in the cells of an UICollectionView? Or only UIImages? I added a button into one of the cells and when I ran the iOS simulator nothing appeared. I also just dragged in an UICollectionView and I am not using an UICollectionView view controller. I dragged the UICollectionView into code as an outlet too and constrained the view, cell and button. Attached is a screenshot of my view controller and iOS simulator. Thanks!!
I was recently new to collection views, and they can be confusing. I found a video tutorial that explains it all really well, but it was not updated for Swift 3 so I wrote made this GitHub project to help explain it to new users.
You can certainly add buttons to to the cells of a UICollectionView. Each cell is like a little UIView in and of itself. However, I believe you need to create a new class for the cell and create an IBOutlet for the button. You also need to create a couple of functions inside your main ViewController.swift file to actually view the UICollectionView. It can be complicated at first, but stick it out! In a little while, you'll be able to do them with ease. Follow the tutorial in a new project to practice, then you might figure out what the problem is.
Sorry that that last one was unhelpful, I'm new to this. Thanks for the tip, manetsus!
I created a new project and tried to add a button to the UICollectionViewCell. Here's what I did:
I added a button to the cell, then created an IBAction by control+dragging from the button to ViewController.swift. I ran it, and it worked. Each button within the UICollectionView cells performs the IBAction in ViewController.swift.
If you want cell-specific actions, consider using:
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath)
//Do something with the cell...
}
I have an image inside my tableview cell.
What I want to do is when I click on that cell I want to parse both text & image to detail view.
I can do for text but I can't get the point about image.
So, simply my question is how can I parse image inside tableview cell to detail view in iOS.
Thanks
You can use it as the same way you're using it. Use indexPath to specify the row you wanna manipulate.
Here's how you do it. implement UITableViewDelegate in your ViewController, and implement the following method.
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
}
The short answer, you access the image the same way that you set it. In the case of the standard UITableViewCell, it is the imageView property that you used.
For these API type questions though, there is no better place to start, than the documentation