Group Group Group Group Group Group Group Group Group

Reproducing Popular iOS Controls - Part 30: | Ray Wenderlich Videos

In this challenge you'll implement the half-way dragged anchor point for the draggable controller.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5298-reproducing-popular-ios-controls/lessons/30
1 Like

I’m having some trouble with the search view jumping around when I am dragging it. Sometimes it snaps to fully open, and back to where my finger is in a split second, which feels very jarring. I thought it was maybe something I hadn’t done correctly when following the videos, but downloaded the sample code and it’s doing it in that too. Anyone else have this issue?

Testing on iPhone X device btw

Yeah, I’m having the same issue

It happens when you interrupt the animation. This is becuase you only update the draggablePosition when animatingPosition == .end.
You can calculate the new draggablePosition before interrupting the animation and update animatingPosition with the result.

How to make map interactive when draggable controller is in collapsed or half state?
I am trying to pan on the map but it seems that interactions to presenting controller are disabled.

Hey!

I responded to a very similar question here: Reproducing Popular iOS Controls - Part 29: | Ray Wenderlich Videos

It should solve your problems :slight_smile:

@mennabah’s answer is correct!

In the animate(to position:) method in the DraggablePresentationController change this part:

animator.addCompletion { (animatingPosition) in
      if animatingPosition == .end {
        self.draggablePosition = position
      }
    } 

With:
draggablePosition = position

I am facing multiple issues while compiling it with xCode 10 beta, issue like NSLayoutConstraint, UIButton with type and more… Not able to to compile the AppStore animation source code… (Sequence : 27), Can you help?

@leamars Can you please help with this when you get a chance? Thank you - much appreciated! :]

Hi @vinaychopra, could you be a little more specific about the issues you’re getting? Maybe post the full error message. Are you sure you’re compiling with Swift 4+? I just did a fresh install of Xcode 10, Beta 6 and downloaded the project files from this video and both the starter & final project compile and run just fine for me.

@leamars is it possible to have a version where the location table view will scroll once it reaches the top most scroll point?

That’s definitely possible, but out of the scope of this video, unfortunately.

Could you point me in a direction to get that started? Would I have to turn off the pan gesture for the transition once you reach the top to allow the table view to scroll? Or somehow forward those events to the table views pan gesture recognizer?

@leamars Do you have any feedback about this? Thank you - much appreciated! :]

Hey! I think there’s probably a couple of different approaches you can take.

For example, one could be that you could track the scrolling on the presentation controller, and once we know it has reached the top, you send a notification to the tableview that:

  1. It CAN scroll
  2. It SHOULD scroll, and pass in the value of how much it should scroll by, based on how much the presentation controller would scroll by in the pan gesture recognizer method.

This is if you’re talking about making sure that there’s scrolling feedback not the tableview at the top stopping point, as in… once you scroll to the top, the presentation controller stops, but the table view will absorb (= show) the scrolling the user might be expecting to see.

If you’re talking about simply making sure that the tableView knows how to scroll, I recommend turning off and on the multiple gesture recognition on the presentation controller by conforming to the UIGestureRecognizerDelegate. So you’d again need some sort of mechanism to communicate the fact that the presentation controller has reached the top TO the tableView.

When the presentation controller reaches the top of the table view you ENABLE tableView scrolling AND presentationController scrolling. If the tableView gets scrolled up, you should DISABLE presentationController scrolling, as the user would only expect to be moving the tableView as they dragged down, but when the tableView reached its top again, you have to make sure to ENABLE the presentationController scrolling so from that point on the user can scroll down = drag down the presentation controller, or scroll up = drag up the tableView.

I hope this helped and made sense! Let me know if things are still unclear and I’ll try to explain myself better :slight_smile:

hey @leamars ! you are a rock star !! thanks for all the fixes and tricks to this video to make it better :slight_smile:

1 Like

I fully understand you, in theory =) Can you please help with this in practice:

  1. Where (I think in LocationViewController) I need to catch if table on the top.
  2. Which method help me to check is table view is first item, or it scrolled down
  3. How I can disable / enable presentationController scrolling

Thanks =))

Ok, little brainstorm time and that’s what I’ve got:

  1. Add special function to DraggablePresentationController, that’s on/off tableView Interaction by position
    private func tableInteraction(position: DraggablePosition) {
    if let view = presentedViewController as? LocationsViewController {
    if position == .open {
    view.tableView.isUserInteractionEnabled = true
    } else {
    view.tableView.isUserInteractionEnabled = false
    }
    }
    }

  2. add this code to and of userDidPan method:
    tableInteraction(position: draggablePosition)

  3. Add check code, if table is scrolled full up in extension of LocationsViewController: UITableViewDelegate

func scrollViewDidScroll(_ scrollView: UIScrollView) {
if (scrollView.contentOffset.y < 0) {
tableView.isUserInteractionEnabled = false
}
}

  1. That’s it =)

But it is some lags: you need pull up table view twice - first time is’t check that, table view is scrolled up and turn off userInteraction. In second swipe I can interact with presentation methods.

Some have any idea how make it in one scroll?

@leamars Can you please help with this when you get a chance? Thank you - much appreciated! :]

Could you update source code to support Scrolling on TableViewController?