swiping image using collectionview in swift - ios

I have some images showing on collection view cell. I am swiping it horizontally. I want the next or the previous image to be shown, by swiping it to right or left but it is swiping like the image attached.
My image:
In this image, two images are there.
How to do it so that by swiping one image will come one after another without not more than one image at a time on the screen?

I think I understand what you're asking. You want only 1 photo to show up, and take up the whole screen, and when you swipe it goes to the next image and snaps it into place? This would just be as simple as:
Making sure your UICollectionViewCell width is the same as the collection view's width.
Enabling paging on the collection view. If you are using Storyboard just select your UICollectionView and check the checkbox labeled "Paging Enabled". To do it programmatically you can just set collectionView.isPagingEnabled = true.

Related

Pan gesture in UITableViewCell that can move image view all over tableview without going beneath the cell

I am trying to create a tinder like swipe left and right in UITableView cell. Here, the tableview cell contains an image view which I can move around with pan gesture. When I initiate the gesture on the image view, I want to move it freely over my device screen.
I am facing the problem that when I move the image view around it goes below the current cell. How can I bring the image view over all others so it doesn't go below the cell frame?
I tried using view.bringSubviewToFront but it doesn't work.
Please suggest a way I can achieve this.
An image view still contained in a cell is not going to be reliably brought on top of all other relevant views. You will have to move that view from the cell to the table view's parent view while dragging (and then return it to the cell if necessary at the end).
You will probably want to look into UIView.convert(_:from:) to figure out the frame to move the image view to in the parent view.

Adding Animating button to each image in UICollectionviewcell just like iPhone Photo App

I'm in the process of creating iPhone photo App like application.In iPhone Photo App on selecting a image -> Tapping share button -> Rotate the device to landscape, we get a selection button at the bottom of all the image items. The selection button frame gets animated when the UICollectionviewCell is scrolled I would like to achieve the same behavior in my app.Any pointers would be really helpful.
Use the scroll view delegate to detect when the user is scrolling. You get a scrollViewDidScroll: event every instant the user scrolls at all. This allows you to figure out whether the button for one of the cells is being moved off the visible area of the screen. If it is, move it the other way to compensate and thus keep it on the screen.
A really useful trick is, once the cell is moving off the screen, to rejigger the button's constraints so that it is constrained to the window (or the root view). This means that it stays still while the scroll view scrolls, even though it is a subview of the cell!
Of course you also have to detect when we have scrolled so far that the button has reached the other edge of the cell, and "let go" of it - allow it to scroll with the cell once again.

Trying to mask a UIImage to display UITableViewCell contents behind it while scrolling UITableView in iOS

I am building an application where I have a ruler (that is a UIImage) that I use to scroll a UITableView. My UITableView has UILabels on each cell that display text. When the user leaves the ruler over a cell, the ruler has on it a UILabel that displays the contents of the UITableViewCell that it is over top of. All of this functionality is in place, and is working fine.
What I would like to do is when I scroll the ruler up or down, is to be able to view the contents of the table rows behind it dynamically while "the ruler is moving", so that the user can see right through the ruler. As a concept, I realize that this technique is called "masking", but normally "masking" is done using two images. What I'm trying to do is use a UIImage that has a UILabel on top of it, to display the contents of the rows behind it while it is moving. Can anyone show me how to do this, or point me in the right direction?
Here is an image of what it is I am trying to implement:
If you look at the image that I am using, the ruler image is partially hiding the bottom of the text in the third row, and partially hiding the top of the text in the fourth row. I would like the ruler to display the bottom of the text in row 3, and the top of the text in row 4 rather than hiding it when it is in this transition state.

ios set background of a UITableViewCell

If you have seen the mailbox app you can swipe cells left and right and they have a UIView underneath that like green with a checkmark or whatever. I want to do this same thing. I have a tableView with custom cells that have gesture recognizers to animate/swipe them left and right but I can't figure out how to place a background underneath them. Does anyone know how to do this?
It might work if you add the subview and then bring the cell's content view above it, and then slide the content view over.
You could also just have a mask that clips the the visibility of your button container, and then animate the size of the mask so that it becomes visible as your cell content slides away.
You would want to add the container on the swipe before the animation starts, and then remove it after the animation stops when hiding it.
If placing it beneath the content view doesn't work, then use the mask, which will.

UICollectionView with subviews only redraws when reappearing

I'm currently building an app that uses a collection view showing images, among other stuff, inside cells.
The controller dequeues a cell, sets an image, and calls a method to change the frame of the image.
I change the image position and size like so:
[imageView setFrame:CGRectMake(imageViewXOrigin,
imageViewYOrigin,
imageViewWidth,
imageViewHeight)];
This is after calculating all 4 values.
After that, the controller returns the cell, and it gets drawn on screen.
The problem is that it's drawn using the old dimensions, and only after scrolling the cell out of the screen and scrolling it back in again will it display correctly. How do I fix this?
Using a standard storyboard mode is out of the question, because I want the image to be an aspect fit bottom left, which can't be accomplished by using the storyboard.
How do I fix this?

Resources