Swift; is scrollView with tableView feasible? - ios

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

Related

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

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?

Swift: UITableView scrolls slowly when embedded in ContainerView

I have two container views controlled by a segment controller. When the selected index changes, one view is set hidden and the other one is set visible.
One view contains a tableview, and the other one is a Google Maps view. I tried to remove the Google Maps view completely to see if the scrolling in the tableview would be better, and that fixed the laggy scrolling. So I know that it is the hidden mapView that makes the tableview scroll slowly.
My question is: How can I keep both container views and still have smooth scrolling when the tableView is visible? Setting the container view with the mapView to hidden does not work.
If anyone else has this problem, try to follow this blog and add the views by code instead of using container views in IB. It fixed the problem, and the tableview now scrolls like a pro!
cocoacasts.com/managing-view-controllers-with-container-view-controllers/

Swift: Did Tumblr add a UICollectionView in a UIScrollView?

I've been trying to replicate this effect for a couple days which was inspired by Tumblr.
I've previously asked questions on here with different approaches of the same problem but to no avail. I'm just curious as to how the engineers at Tumblr created a horizontal collection view, with two vertical collection views, and is able to scroll down without affecting the view above (without resetting the position of the view when you scroll vertically in a different tab).
Header Views
I tried this, but the header view was isolated and I had to scroll to the right to see the collectionView cells. This did not work.
Changing the topLayoutConstraint constant of my UIView (not cv header) with respect to the contentOffSet of the vertical collectionView.
This almost got the effect I wanted, except that when I scrolled horizontally, there was a huge gap between my collection view and if I scrolled in that new tab, the UIView would appear again because, again, topLayoutConstraint gets scrolled up depending on the contentOffSet of my vertical collectionView contentOffset.
Changing the position of the UICollectionView frame, and scrolling the super view up simultaneously with NSNotificationCenter.
Alas, this method did the same as method #2, except that the vertical collection view cells scrolled faster than the super view.
I ran out of options to make this work so I will show you in detail what's attempted to be replicated (also note the scroll bar on the right):
Note when I scroll down the first tab. I switch, and then scroll down further. Originally, as I've said, there would be a gap between the second main CV, and when I scrolled, the view would reposition as if were scrolling up again. On here, the view on top keeps going up. So I'm curious as to what method Tumblr engineers used to do this. UICollectionView inside UIScrollView? Other suggestions?
I believe there is no UICollectionView involved. It looks like UIPageViewController and each its page is a UITableView.
Perhaps the UIPageViewController sits in a UITableView as well - the header also moves up when you scroll. This main table has only one cell (and a header) which is occupied by the UIPageViewController.
Hope it helps.

Make a UIView receive taps but pass swipes to the underlying view

I've got a UITableView and a big "button" view in front of it. The "button" view, which has transparent areas, should be able to response to a tap. But enabling user interaction for this view blocks any scrolling touches from getting to the table view located under the "button" view.
The upper view is a UIView (not UIButton). Given how the two views work together, the upper view is essentially part of what's going on with the table view and reacts to the table view being scrolled. But scrolling is the main thing and I'd like the user to have the largest scrolling area possible.
How do I best resolve this conflict so that the table view is scrollable as usual?
I guess you could subclass your UIButton and UITableView common superview, and override its hitTest:withEvent: to verify which view is hit, something like if you are in a clear or an opaque part of the button?
As pbush25 is mentionning however, it goes more or less against Apple's recommendation.

UITableViewCell Editing is very difficult to show

I want my table view cell to show the Delete bar on the right side when the user swipes. However, the table view is in a UIScrollView, and although it is at the far right side, and swiping left does not move the scroll view, the table view cell makes it difficult to edit.
In order to trigger the swipe for editing, I must swipe very fast and in a perfectly horizontal line. The speed required is far more than you can expect users to even want to do, and would not be expected at all from a user's perspective.
I believe the scroll view is the cause, but I cannot be certain. No gesture recognizer is present.
How can I prevent the scroll view from mucking up this experience?
Putting a tableView or webView in a scrollView is not advised, because of the exact problem you are having. Your best bet is to find a way around putting it in a scrollView. Other than modifying your tableView to not be in the scrollView, you might try moving your tableView to the front. [superView bringSubviewToFront:tableView]; hope this helps.
You could try using the gesture recognizer delegate methods for this. I don't have Xcode in front of me, but if you use gestureRecognizer:shouldRequireFailureOfGestureRecognizer: and just fail the scrollView's swiping gesture if the gesture recognized is that of the swiping of the table view cell. Check UIGestureRecognizerDelegate in the docs.

Resources