Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Completion event #20

Merged
merged 2 commits into from
May 30, 2013
Merged

Completion event #20

merged 2 commits into from
May 30, 2013

Conversation

kcharwood
Copy link
Contributor

Hello!
There is a method:
toggleDrawerSide: animated: completion:
called when user press open button. Within completion block I can detect when it opened up.

The question is: how can I detect it opened when user performed swipe gesture or finished dragging the open button?

@larsacus
Copy link
Contributor

More generically, are you looking for a completion event to be called when the animation for the view controller you are explicitly telling to display is complete?

For example, the right drawer is open, but the center view is still visible. You then call to close the right drawer so the center will become the main view controller (so no viewWillAppear:/viewDidAppear: methods will be called on the center). Are you looking to detect when that center controller is going to become the primary controller?

@arsenykorotaev
Copy link
Author

I'm looking for detect when left or right are become active i.e. finished their transition. "toggleDrawerSide:animated:completion:" method has a block argument which called when transition is finished. In your example this method explicitly called when user press button to open right(left) controller. It's solve a part of the problem. But it's also possible to open left(right) controller with swipe gesture. I want to set the same completion block for swipe gesture.

@kcharwood
Copy link
Contributor

Hey @arsenykorotaev,

What exactly are you wanting to do in that case? I.e. update a table, display an animation, etc.

Still trying to think about what would be the best solution for you.

@arsenykorotaev
Copy link
Author

I want to setup video capture session.

Good scenario:
Center view is active view.
User press right button. The following code executed:
-(void)rightDrawerButtonPress:(id)sender{
[self.mm_drawerController toggleDrawerSide:MMDrawerSideRight animated:YES completion:^(BOOL finished) {
if (finished) {
[self startCaptureSession];
}
}];
}

Thats works fine.

Bad scenario:
Center view is active view.
User perform right-to-left swipe gesture or dragging right button.
Where can I start execute [self startCaptureSession];?

Notice startCaptureSession execute [AVCaptureSession startSession] method which take up to ~1-1.5s to complete.

@kcharwood
Copy link
Contributor

I put together a potential option here f94c3f8

@larsacus thoughts?

@larsacus
Copy link
Contributor

It's almost as if something needs to be called on the view controller that the completion handler is being called for. Almost like the view lifecycle methods (viewDidAppear:, etc), but for our gesture completion.

@larsacus
Copy link
Contributor

I think this is a good solution. Let me propose this, however. What if instead of the block that you've defined here, we defined a category method on all UIViewController instances like so:

- (void)mm_drawerController:(MMDrawerController *)drawerController gestureCompletedWithState:(BOOL)visibleState{
    /** Do stuff related to view controller after being shown/hidden from gesture */
}

This way you wouldn't need to hold onto a block for what happens for a view controller. Each view controller could handle what happens when that gesture is completed, so different actions could be handled by each view controller simultaneously.

What are your thoughts on this?

@kcharwood
Copy link
Contributor

I'm torn on that one. Not sure I like it.

I think it would be better to create a subclass of MMDrawerController, and let that subclass be your air traffic control man by setting that block and manipulating its children appropriately. Thoughts?

@larsacus
Copy link
Contributor

Ok I can see this. Any specific examples I can think of in favor of the category method would be mitigated by use of viewDidDisappear: on the drawers and subclassing MMDrawerController. We currently don't have any rules for what to do/not do when subclassing MMDrawerController if we're going to push developers this direction.

@kcharwood
Copy link
Contributor

Ya we should put some documentation together on that. I've also been following @steipete's great work here with NS_REQUIRES_SUPER, which would come in handy here as well.

https://gist.github.com/steipete/5626678

@larsacus
Copy link
Contributor

Yeah I ran into that gist earlier this week and it's intrigued me as I've never seen such an attribute documented before. I'm creating an issue right now to start discussion about subclassing rules and documentation.

@larsacus
Copy link
Contributor

Created #36 to define subclassing procedures. Feel free to add input to make it easier for everyone since we all have different goals as to what this is supposed to do.

@kcharwood
Copy link
Contributor

@larsacus What do you think about this pull request for this specific feature?

@larsacus
Copy link
Contributor

I think this looks good for this case. If the developer requires multiple callbacks or to be "air traffic controller", a subclass is in order.

I approve.

kcharwood added a commit that referenced this pull request May 30, 2013
Support for a callback block when a gesture event is completed.
@kcharwood kcharwood merged commit d37b0ac into master May 30, 2013
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants