honcheng / PaperFoldMenuController

A navigation menu on the left of the screen using on PaperFold
Other
436 stars 90 forks source link

Forever loop in unfoldLeftView #8

Open flypigz opened 11 years ago

flypigz commented 11 years ago

Actually this is an issue of PaperFold, but I can reproduce it easily with this PaperFoldMenuController demo.

Issue reproduce percentage: 100%

Issue reproduce steps using the demo project:

  1. add one left navigation bar button ("Show Menu") for the center view controller

1.1 update two methods below in PaperFoldMenuController.m

1.2 add below methods in PaperFoldMenuController.m

pragma mark

pragma mark - Bar Button Action

///////////////////////////////////////////////////////////////////////////////////////////////////

after this, you can use the "Show menu" button to show the left menu, but you can't use it to hide the left menu with above code.

  1. in IOS6, we will use pull down gesture to display (pull down from the status bar) the system notification center, right? but if user does not execute this gesture correctly, it will leak to an issue:

2.1 put one finger in the Navigation bar of center view controller 2.2 pull down you finger but DO NOT exceed the bounds of the navigation bar (i.e. limit you pull down gesture in the navigation bar) 2.3 press the "Show Menu" bar button, which will invoke "[self showMenu:YES animated:YES];" method, but it won't work any more, and it will loop in the PaperFoldView::unfoldLeftView method forever....

I guess this happens because you capture the pull down gesture in somewhere, maybe this happens after you merged the code of PaperFold top and bottom fold feature (not sure if this feature has been merged to the main branch of PaperFold), and it break the codes.

Please msg me if you have any question about the issue reproduction.

Thanks in advanced.

flypigz commented 11 years ago

The root cause should be

  1. when pan horizontally inside the navigation bar, the self.paperFoldInitialPanDirection will be set as PaperFoldInitialPanDirectionVertical
  2. when press the "Show Menu" Bar Button, the callStack would be

1)PaperFoldMenuController: showMenu:animated 2) PaperFoldView:: setPaperFoldState:PaperFoldStateLeftUnfolded animated:animated (animated is YES) 3) PaperFoldView:: setPaperFoldState:PaperFoldStateLeftUnfolded 4) PaperFoldView:: unfoldLeftView 5) PaperFoldView:: animateWithContentOffset:panned (the panned will be set as NO)

because the self.paperFoldInitialPanDirection is set as PaperFoldInitialPanDirectionVertical so we are going into the wrong code path, actually it should run into the code path of "if (self.paperFoldInitialPanDirection==PaperFoldInitialPanDirectionHorizontal)"

Fix: ??

set the self.paperFoldInitialPanDirection as PaperFoldInitialPanDirectionHorizontal before invoking animateWithContentOffset:panned method.

// unfold the left view

Further Investigation

I am not sure if there would be some smilar issues for unfoldTopView or button view or right view, but you can use the similar solution to fix it. This only happens when invoking the PaperFoldView:: setPaperFoldState: method, because we directly re-used the last self.paperFoldInitialPanDirection value which is set in the onContentViewPanned method, and this value is obsolete.

For the pan to show top/bottom/left/right view, there is no such issue, because the self.paperFoldInitialPanDirection is updated each time.

honcheng commented 11 years ago

Wow. Thanks. Let me read this... and get back to you,

honcheng commented 11 years ago

Do u have a sample project u can send me?

flypigz commented 11 years ago

I created a resp, try https://github.com/flypigz/PaperFoldMenuController-Forever-Loop, test step

  1. pan vertically inside the navigation bar
  2. click "Menu" button on top left
  3. check debug log, there should show the loop message
marcobrambilla commented 10 years ago

FYI I ran into the exact same problem... the fix proposed by @flypigz solved the issue.