andreamazz / AMScrollingNavbar

Scrollable UINavigationBar that follows the scrolling of a UIScrollView
MIT License
6.05k stars 633 forks source link

Can not move rows in UITableView #340

Closed StefaniOSApps closed 6 years ago

StefaniOSApps commented 6 years ago

Describe the bug You can not move rows in UITableview

Demo Project https://github.com/StefaniOSApps/Example Run Demo

Expected behavior Can move rows to each position.

StefaniOSApps commented 6 years ago

How can we check if a UITableViewCell is moving in scrolling view ? @andreamazz

I think the solution we can found in

open func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        guard let gestureRecognizer = gestureRecognizer as? UIPanGestureRecognizer else { return true }
        let velocity = gestureRecognizer.velocity(in: gestureRecognizer.view)
        return abs(velocity.y) > abs(velocity.x)
    }

how can we can proof if a UITableViewCell is moving ?

andreamazz commented 6 years ago

Checkout latest commit

StefaniOSApps commented 6 years ago

Reopen it

 if let tableView = scrollableView as? UITableView, tableView.isEditing {
            return
        }

it is not the best solution, because the UITableView with tableView.isEditing = true, does not allow to hide the NavBar (always).

I hope you know that tableView.isEditing is not the same one as moving UITableViewCell It must be asked directly if a cell is being moved at this moment

StefaniOSApps commented 6 years ago

i have been updated the demo project with the current solution

https://github.com/StefaniOSApps/Example check it out

andreamazz commented 6 years ago

I preferred this route for a reason: it's a common pattern to have the button to end the editing mode in the navigation bar, it might be annoying to force the user to scroll down to make it visible. It's safe to assume that during the editing phase, having the navigation bar visible is preferred.

StefaniOSApps commented 6 years ago

I have the problem that I want to slide a cell in a section to delete and move in another section cells with each other.

Can you make it optional? That would be the best way.

showAlwaysNavigationBarWhileEditingmode = true / false

andreamazz commented 6 years ago

I could, but the starting issue remains, I'm not aware of a public API that tells you whether a cell is being dragged or not. I'll do some digging and let you know.

andreamazz commented 6 years ago

Maybe checking if a single cell is both in editing and highlighted? 🤔

StefaniOSApps commented 6 years ago

I had already tested everything. I also checked the alpha value of the cell subviews, but without success.

I have solved this problem:

ADD

/**
     Defaults to `true`
     */
    open var showAlwaysNavigationBarWhileEditing = true

CHANGED

if let tableView = scrollableView as? UITableView, tableView.isEditing, showAlwaysNavigationBarWhileEditing {
            return
}

SET

[(ScrollingNavigationController *)self.navigationController setShowAlwaysNavigationBarWhileEditing:true];

i have been updated the demo project with the current solution

https://github.com/StefaniOSApps/Example check it out

andreamazz commented 6 years ago

That's fine, but if the library user doesn't set that flag, the editing behavior will be broken like in your starting project. I rather have a more robust solution, I'll let you know if I can find it, if I can't I'll add that flag.

StefaniOSApps commented 6 years ago

No, I do not think so. The function gestureRecognizer?.cancelsTouchesInView = false is already enough, so that everything works.

The user can set [ScrollingNavigationController setShowAlwaysNavBarWhileEditing:true]in his own Project (default is true).

I think this solution is the best and my fork (branch master) use this way.

andreamazz commented 6 years ago

Ok, sounds reasonable. Added shouldScrollWhenTableviewIsEditing in the latest commit.

StefaniOSApps commented 6 years ago

thanks