Detect swipe events on UIPageView below UITableView - ios

So my problem is the following:
I have a UIViewController, in it I have defined a UIPageViewController and added its view to the hierarchy and on top of that I have added an UITableView.
What I would like is to be able to scroll my UITableView (that part works) but also to be able to swipe to change the slides of my UIPageViewController.
My problem is that the UIPageViewController doesn't detect the swipe gesture at all. If I remove the UITableView it works all right of course.
My question is the following: is there any way to pass the swipe events from the UITableView to the UIPageViewController so both would receive their intended gestures ?

You would need to have the tableView inside your page view (in the content view controller for a specific page).
If you have two views on top of each other the front one will intercept all the touches and no actions will make it through to the lower views.
Try setting user interaction on the tableView to false to see what I am talking about. Of course this will cause the tableView to become unresponsive. You will need to implement this a different way.

Related

Swipe to the same Viewcontroller

I am trying to implement a left-right swipe gesture to navigate between an array of objects, that i can change the properties and take actions. The navigation is more of a previous-next approach. I have a table view that segues to this Viewcontroller, and i would like the user to check the next object without getting back to the TableViewcontroller. What is the best approach to implement this?
I know PageController isn't ideal in my situation as i'm not navigating between different VCs.
A page view controller is the best way. Make the views view controllers instead. It does all the work for you.
Failing that you could use a collection view with a custom flow layout.
Failing that, you could roll your own custom view controller that implemented this feature.
EDIT:
Based on your screenshot, where you say "swipe back and forth to move between rows of a table view" you need a collection view. Table views scroll up and down between rows. That's what they are made to do, and trying to implement a swipe interface to instead scroll side-to-side is crazy. Simply use a collection view configured for horizontal scrolling between cells.

Prefer swipe to delete over a competing swipe gesture

So I have a tableViewController inside a XLPagerTabStrip view controller, basically a pod which allows me to swipe between child view controllers left and right. The problem is that I want to disable the view controller scroll when the user swipes on a cell on my tableView. In this case I want him to be able to see the delete option, instead of changing the viewController itself. Is this possible? Currently, I see the delete button only if I swipe really, really fast and in all other scenarios, the entire viewController is swiped away.
I don't believe there is any sort of preference property for UIGestures. Instead, I believe the rule is the first gesture added takes precedent. However, in your specific circumstance with XLPagerTabStrip, you can simply disable scrolling in the interface builder for your 'containerView' (subclass of UIScrollView). That solved the problem for me anyway, having my children view controllers' UITableViews actions appearing correctly.

Swift: UIPageViewController - Navigate view controllers with swipe from edge of screen

I am new to UIPageViewControllers and can't seem to find a solution elsewhere. I have a working UIPageViewController with 3 different viewControllers. Right now you can navigate to a different viewController by swiping left or right starting at any point on the screen. However, I only want to navigate to a different viewController when I swipe over from the right or left edge of the screen. Similar to how the Screen Edge Pan Gesture works. Is this possible? If so, how would I go about implementing this in my program.
What I do in this situation is to attach gesture recognizers to the views of the "3 different viewControllers", that is, the child view controllers of the page view controller. These gesture recognizers' action methods post notifications. In the view controller that controls the page view controller, I receive these notifications and call setViewControllers:direction:animated: to perform the appropriate slide.
UIPageViewController has and embedded gesture recognizers that to the trick. Normally you have no influence on them. You could get to them by calling gestureRecognizers method on UIPageViewController's view and see what you can do with them from there.

iOS Snapchat Style - UIPanGestureRecognizer Within UITableViewCell And UIPageViewController

I'd like to give a go at implementing the same functionality of Snapchat specific to the way you get into a text chat with a friend in that app.
I have three view controllers in a UIPageViewController. The middle view controller is a UITableViewController with an expandable cell and five subcells that appear when the cell is expanded. I have a UIPanGestureRecognizer in each of the subcells where as you slide to the left on a cell, a button is revealed. However, both the pan gesture recognizer and the UIPageController sliding to another view controller are happening at the same time. How do I disable the UIPageViewController sliding until a user is sliding the UITableViewCell?
I'd like to have it just like Snapchat by doing the following:
Disable the UIPageViewController sliding. Then, as a user is sliding a UITableViewCell with the UIPanGestureRecognizer, when the button is fully revealed, THEN switch the UIPageViewController sliding back ON so when the user slides further, it starts to slide to the next view controller.
I think that I'll have to put some of this in the CustomTableViewCellDelegate of my CustomTableViewCell. Any ideas on how to implement this? I can email my Xcode project to recreate the problem if need be. Thanks.
EDIT: Finally learned how to upload my Xcode Project to GitHub. My project can be found on this link https://github.com/cnowak7/PanGestureTest to recreate the problem.

Sliding a UIViewController to pop - as in the Readability app

I'm trying to emulate the sliding UIViewController as seen in the Readability app. You can drag a page to the right and it pops the current view off the stack to go back to parent UIViewController with a sliding animation as in the image: the right-most view was on the top and is being dragged right-wards showing the original table on the left.
I've tried a few of the slidingUIViewController solutions such as ECSlidingViewController but they try to emulate the Facebook/Path behaviour of partially sliding a slidingUIViewController on top of another which is not what Readability does.
I've also tried a standard horizontally scrolling UIScrollView but scrolls like the pages are joined at the sides, as opposed to sliding one view over another.
Does anyone know how they did this?
This can be easily accomplished in few steps. I'm not going to write down all the code you need to write in order to do it, but just the steps you need to take. I will use a master-details terminology where the master view is the one from which you want to present a details view and the details view is of course the one at the top of the navigation stack.
When you want to present the detail view:
1) create an instance of the UIViewController that handles the interactions with the detailView. On iOS 5+ you can store this instance in the childrenViewControllers #property on the master's viewController. If you support a lower OS you should store the instance in an ivar.
2) set the detailView's frame to be outside the screen's bounds; add to detailView a shadow for graphical purposes. Finally add the detailView as a subview of the masterView.
3) (optional) add a pan gesture recognizer to the detailView in order to allow the user to swipe the view back and dismiss it.
4) animate the detailView in the screen's bounds. Make sure the interactions with the view below are disabled (be careful not to disable also the interactions with the detailsView!)
When you want to dismiss the detail view:
1) animate the detailView outside the screen's bounds.
2) remove it from it's superview and delete the reference to it's viewController.
3) re-enable the user interaction with the master view.

Resources