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

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.

Related

Swift; is scrollView with tableView feasible?

I've have been trying for a while now, to implement a specific behavior in my app. On the initial view of my app, there must be a logo(imageView), a label and a textField. It should be possible to scroll down from the initial view, to a tableView. while the user scrolls down, the label in moved up in the window, to form a search field for the tableView. Then the scrollView should lock to the part with the tableView, and it should only be possible to scroll back up, if dragging elsewhere than the tableView.
What is best practice for doing as described?
The image show (only for illustration, i havn't been using story board when trying to implement it) an overview of the problem:
The way I've tried to do this so far, is by embedding the tableView in a scrollView (as seen on image), enabling paging on the scrollView, and than disabling scrolling on the scrollView, when the buttom part has been reached. I've added a gesture reconizer on the part with of the screen with the textField.
These two posts (Scrollview with embedded tableview and Use Pan Recognizer to Control ScrollView) descripe i further detail what i've tried so far.
But the question is more to, is there an alternate solution for making behaviour descriped above?
Maybe interactive animated transitioning between view controllers somehow?
YES there are! Implement a table view with a header view. And remove the scroll view.
self.tableView.tableHeaderView = topView
where topView will be the view wish as the UIImage, the label and textField

Custom UITableViewCell layer cutoff

I have a UITableView with custom cells. In the awakeFromNib of the cell custom class I add the cell labels etc. using AutoLayout. They display fine when viewed first time.
(Blue rectangle is a single UITableViewCell)
The problem is that after I swipe the table view so that some cells goes offscreen then back again (i.e. cells are re-layout) the cell layer gets cutoff.
Another way to debug is to go to Xcode, Click Debug>View Debugging>Capture View Hierarchy on Xcode 6+. It looks like there is possibly an unused view being added to the bottom left corner of your view? Try the view debugging to see if that's the case.

Scrolling up UICollectionView don't move a UIView above it

I am working in a profile ViewController. This profile has a main image in a UIView subclass and a CollectionView gallery with some images. I would like to be able to scroll up the UICollectionView and move the UIView too, and if I scroll down, I want to watch again the UIView when the collectionView first item is showed again.
I have tried to do this adding the collectionView and the UIView to a ScrollView, but the UIView only scroll up if I touch it.
In this picture you can see my problem
Thank you in advance
You need to make the view at the top a Header View of the collection view.
Essentially it needs to be an actual part of the collection view if you want this action. (That's the easiest way anyway).
So the collection view will take up the whole screen but it will have a header view. Then when you scroll the collection view the header will move out of view and then come back in when you scroll down again.

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.

UITableViewCell horizontal custom swip- to-delete effect

I have a UITableView and would like to have a custom way to delete my cells. When someone swipe on it, the cell would move horizontally on the side and disappear.
Exactly like the multitasking menu on iOS 7 (http://movies.apple.com/media/us/ios/ios7/f34c5445-5a9c-4b3a-9556-8efe89147559/shared_multitasking/shared_multitasking_2x.mp4), but instead of swiping vertically, it would be horizontal.
Does any one knows how to do that? Should I just detect a swipe and change the frame of my cell with a 1 sec animation? Or are there nice subclasses of UITableViewCell you would recommend?
I just threw together a very basic example of how to do this and posted it here: https://github.com/NSPostWhenIdle/MMSwipeToDeleteCollection. Don't expect to be able to drag and drop this into your project and have it work, because quite frankly it probably won't.
The basic idea to create something like this starts with a subclass of UICollectionViewCell that adds a gesture to the cell. In my example, I used a swipe gesture because I'm lazy :p and there is more overhead involved in setting up a pan gesture (which you'll want in your end product) because there is conflict between that pan gesture, and the pan gesture in the collection view's scroll view.
From there it's basically smooth sailing. When the gesture recognizer gets called you animate the cell out the top of the screen. If you set this up with a pan gesture, you'll need to configure this to drag the cell, and animate up or down upon completion, but in my swiping example, the cell moves to just out the top (of the 4 inch simulator, I used static values).
Then all that's left to do is some clean up. Once the cell has exited the screen you can safely delete it from your datasource and then from the collection view. (I used notification center do alert the collection view, but you should probably make a protocol) The only issue I had with this was that the cell animated back down while fading out as part of the stock deletion animation. Setting its alpha to 0 after it leaves the screen solves this problem.

Resources