iOS - Detect panGesture on edge of screen to open side menu + UICollectionView with horizontal scrolling - ios

I just have an UICollectionView inside my UIViewController.
I am using SWRevealViewController to open left/right side menu. I can set its panGestureRecognizer to provide full screen panning.
view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
The following method will provide a panGestureRecognizer suitable
to be added to any view in order to perform usual drag and swipe
gestures to reveal the rear views. This is usually added to the top
bar of a front controller, but it can be added to your
frontViewController view or to the reveal controller view to provide
full screen panning. By default, the panGestureRecognizer is added
to the view containing the front controller view. To keep this default
behavior you still need to call this method, just don't add it to
any of your views. The default setup allows you to dissable user
interactions on your controller views without affecting the
recognizer.
My issue is that on a specific cell of my UICollectionView I don't have any spacing on the edges. The cellWidth = collectionView.bounds.size.width AND this cell contains an UICollectionView with horizontal scrolling.
Instead of opening my left/right menu, it just scroll horizontally my UICollectionView.
I would like to handle this scenario:
1: if the panGesture is located within the UICollectionViewCell containing the UICollectionView with horizontal scrolling.
2: detect the gesture location on the horizontal axis, and if it is on the edge of the screen, don't trigger the horizontal scrolling of the UICollectionView but trigger the panGesture to open the menu.
After reading a lot of articles and the official documentation I found this UIScreenEdgePanGestureRecognizer.
But also that this logic should be done by overriding the method shouldReceiveTouch, am I right?
Any hint on how I should implement this ?
EDIT:
After reading the question suggested in the comment, this is what I tried, but it's not working.
let edgePanGesture = UIScreenEdgePanGestureRecognizer()
collectionView.panGestureRecognizer.require(toFail: edgePanGesture)
I set this in my cell containing the horizontal collectionView but it's not working.
I might be missing something, any help?

Related

Pull to refresh for simple UIView

Can anybody advice how to implement pull to refresh functionality on iOS for a simple UIView without UIScrollView?
I've tried to use UIRefreshControll, but it should be added either to UITableView or UIScrollView, but I have just a UIView. When I add UIRefreshControll to UIView my App is crashing.
I do not want to add UIScrollView to the existing layout, because my screen is splitted to two section: top part is UIView and bottom part is UITableView. If I add UIScrollView to the top part I'll have 2 UIScrollView on the same screen, what I think is not good. But I need pull to refresh for the whole screen, to that user can refresh both top and bottom part of the screen.
I'd appreciate any ideas.
My code example:
public override ViewDidLoad()
{
var refresh = new UIRefreshControl();
MyView.Add(refresh); // crash here
//MyView.AddSubview(refresh); // such option also causes crash
}
It can be done in 2 ways :-
(1.) You need to add pan gesture recogniser interactively to UIView and needs to adjust y position of both UIView and UITableview according to pan movement downwards and after some threshold value you have to move UIView and UITableView back to its default position.
NOTE:- In this case, you have to add circular loader animation also, same as how it comes in UIRefreshControl. This will also be a part of interactive pan gesture.
(2.) You can add UIView as a section header of UITableView.

How to enable UITableView swipe to delete along with horizontal page swiping

In one of my app, I am having multiple table views inside a horizontal scroll view. So, user can horizontally swipe between table views. I am not using UIPageViewController for some reason.
The problem that I am facing is that I have swipe to delete feature on my UITableView but does not work when I have multiple pages in the horizontal scroll view.
Is there an elegant way to provide both the features at the same time?
You can subclass UIScrollView and implement UIGestureRecognizerDelegate. Then return true in gestureRecognizer(_:,shouldRecognizeSimultaneouslyWith) for the appropriate recognizers.

Accessibility issue in UIScrollView

In my app we have taken a scrollview with paging enabled inside that i have added multiple custom views which can have multiple individual elements which are all accessible. Now the issue is when accessibility is on and i try to traverse all the elements via right swipe gesture.
Observation: when it comes to last element of first custom view and i perform right swipe gesture it does not jumps the focus to next custom view elements. Any idea how i can make it happen?
I followed voice over can only see a page of a uicollectionview but here there are using collection view and individual elements inside UICollectionViewCell are not accessible
Using paging with a scrollview, the UIPageControl handles movement between the subviews. You really should just leave this control as the accessibility component for navigation as users are familiar with how it works.
https://developer.apple.com/documentation/uikit/uipagecontrol

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

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