MFSideMenu full size pan gesture - objective-c

I use MFSideMenu in my application, and i can show the menu using a pan gesture on the navigation bar only. I would like it to work on the whole screen, like on the facebook app.!
I've tried changing this line (l.39 in MFSideMenuManager.m)
[controller.navigationBar addGestureRecognizer:recognizer];
to this :
[controller.view addGestureRecognizer:recognizer];
but it just won't work.
Do you have any idea of what i should edit for it to work?
Thank you for your help

I finally succeeded making it work. The gesture is actually already implemented but working only if the menu is hidden. We have to remove 2 conditions to make sure it works both ways
There are two lines to edit in the MFSideMenuManager.m
In the gestureRecognizerShouldBegin: method
if([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
if([gestureRecognizer.view isEqual:self.navigationController.view] &&
self.navigationController.menuState != MFSideMenuStateHidden) return YES;
becomes
if([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
if([gestureRecognizer.view isEqual:self.navigationController.view]) return YES;
In the navigationControllerPanned: method, just remove the if line
- (void) navigationControllerPanned:(id)sender {
if(self.navigationController.menuState == MFSideMenuStateHidden) return;
[self handleNavigationBarPan:sender];
}
becomes
- (void) navigationControllerPanned:(id)sender {
[self handleNavigationBarPan:sender];
}
And it works!
It is not a really good practice to edit a library, but it is easy if you want to go further to add a boolean option to MFSideMenu to make it configurable.

I don't know the MFSideMenuManager but if the bar is draggable I expect it to have a UIPanGestureRecognizer with a line
[self.navigationController.navigationBar addGestureRecognizer:gestureRecognizer];
So what you do is replace the navigation bar with the view for the whole navigation controller
[self.navigationController.view addGestureRecognizer:gestureRecognizer];

Related

Hide status bar in iOS7

I need to hide the status-bar on iOS7. I already tried to set:
Status bar is initially hidden
and
View controller-based status bar appearance
into the plist file. Status-bar doesn't appears when app in launched, but when I change view-controller (is a tabbed app) status-bar appears!
I already tried to set
- (BOOL)prefersStatusBarHidden
{
return YES;
}
and
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
in a view-controller, but doesn't works. Any ideas?
Thank you in advance :)
UPDATE
I partially resolve the issue by setting "View controller-based status bar appearance" to "YES" into info.plist and calling the method
- (BOOL)prefersStatusBarHidden
{
return YES;
}
into the view-controller. But now I got another problem: status-bar appears when I launch another controller (UIImagePickerController). I tried to set [myPicker prefersStatusBarHidden]; but it seems to be read-only. Anyone know the solution?
P.S.: UIViewControllerBasedStatusBarAppearance = NO and UIViewControllerBasedStatusBarAppearance = NO are the same thing..
add this key to your info.plist
UIViewControllerBasedStatusBarAppearance = NO
Set
UIViewControllerBasedStatusBarAppearance = YES
in the info.plist and in each controller implement
- (BOOL)prefersStatusBarHidden {
return YES; // or NO
}
Then whenever you need a status bar appearance update (e.g. in the viewDidLoad of a controller) call setNeedsStatusBarAppearanceUpdate.
As per the documentation of setNeedsStatusBarAppearanceUpdate:
Call this method if the view controller's status bar attributes, such as hidden/unhidden status or style, change. If you call this method within an animation block, the changes are animated along with the rest of the animation block.
So for instance
- (void)viewDidLoad {
[super viewDidLoad];
[self setNeedsStatusBarAppearanceUpdate];
...
}
will hide/unhide the status bar (aside from other potential style changes) whenever the view controller's view loads.
Optionally you can also animate the transition wrapping the call in an animation block
- (void)viewDidLoad {
[super viewDidLoad];
[UIView animateWithDuration:0.5 animations:^{
[self setNeedsStatusBarAppearanceUpdate];
}];
...
}

UIButton responds to UIPanGestureRecognizer on top of it

I just added a UIView with UIPanGestureRecognizer on top of my view.
The view has several UIButtons which respond to touchUpInside events.
What's weird is that ever since I brought the UIPanGestureRecognizer, when panning, if the UIButton is right underneath the "Panning view", the button would trigger which is not what I am after.
Of course I could make a BOOL flag for "panning", so that the button won't fire, but it seems to me like bad engineering and surely something I am missing. I guess after the first touch, both views intercept the event.
Is it possible to overcome this?
Thanks
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldReceiveTouch:(UITouch *)touch {
if ([touch.view isKindOfClass:[UIButton class]]) {
return NO;
}
return YES;
}
use this method to differentiate GestureRecognizer and Button Acton.
Hope this helps you.
Not sure if this help
[[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(handlePanned:)];
- (void)handlePanned:(UIPanGestureRecognizer*)thePanner{
if (thePanner.state == UIGestureRecognizerStateChanged ){
//disable button
}else if (thePanner.state == UIGestureRecognizerStateEnded) {
//enable button
}else if ( thePanner.state == UIGestureRecognizerStateFailed ){
//enable button
}
}
you can sort-out your problem by following two tactics:-
1)When adding the gesture in your required view, be sure that it will not added with un-required view, in this case is your UIButton, &;
2)At the method/delegate where you handle the case of detecting the gesture, ie what gesture do, before the implementation you assure that this is not the UIButton.
If you insist, I'll try for sample code.
Have a good day ahead. :)

How to recognize rubbing gesture?

I was wondering how to create some type of recognizer for a rubbing gesture.
You can see this gesture in Talking Tom Cat app and I would love to have this gesture in my clone of the app. Could you please guide me a little?
As I understand it, it is probably a swipe up and swipe down, however I don't know how to implement it the same as in the Talking Tom Cat - that means, playing animation and sound while I am rubbing the character. (I know how to play sound and animation, just don't know how to implement it with this gesture)
Also I am not sure, if it is better done by using UIGestureRecognizer or touchesBegan, Moved, Ended etc.
You could try something like this:
first add gesture recognizer where you are setting up the view.
[myView addGestureRecognizer:[[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(handlePan:)]];
Then add code to handle gestures.
-(void)handlePan:(UIGestureRecognizer *)sender
{
if(sender.state == UIGestureRecognizerStateBegan) {
[self startAnimation];
} else if (sender.state == UIGestureRecognizerStateEnded) {
[self stopAnimation];
}
}
hope that helps.

MKMapView zoom broken after adding a single tab gesture recognizer

I'm working on an application using a map on which the user have to add an annotation. Very simple. Problem is, right after I added a tap recognizer on my map, the zoom supposed to be triggered after a double tap no longer works. It seems to be a pretty common issue, as I found (and tried, I swear) a lot of potential solutions without any success.
The latest solution I tried (and I felt very clever after finding it by myself) was trying to retrieve the "built-in double tap" recognizer of the MkMapView, so I can reuse it in my "single tap" gesture recognizer. This is what I did :
- (void)viewDidLoad {
[super viewDidLoad];
NSArray *gestures = [map gestureRecognizers];
for (UIGestureRecognizer *r in gestures) {
if ([r class] == [UITapGestureRecognizer class]) {
if (2 == [(UITapGestureRecognizer *)r numberOfTapsRequired]) {
builtInDoubleTap = (UITapGestureRecognizer *)r;
NSLog(#"BOOM! Found it!");
return;
}
}
}
NSLog(#"Guess view did load");
[self enableTapRecognizer];
}
And in my "enableTapRecognizer" method :
- (void)enableTapRecognizer {
UITapGestureRecognizer *mapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handlePosition:)];
if(builtInDoubleTap) {
NSLog(#"require to fail builtInDoubleTap");
[mapGestureRecognizer requireGestureRecognizerToFail: builtInDoubleTap];
}
[map addGestureRecognizer: mapGestureRecognizer];
}
Problem is, it never shows my "Boom! Found it!" debug message. How come it can zoom after a double tap without any gesture recognizer? That doesn't really make sense, does it?
(I also tried using a UIGestureRecognizerDelegate so my gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer method returns YES...)
I'm kinda desperate right now, so if somebody has an idea... maybe something wrong in my map configuration?
I'm targeting iOS5 and running latest xCode.
Thanks !

Obj C - resign first responder on touch UIView

I'm trying to get the keyboard to disappear when the screen is touched, a question that is answered all over stackoverflow. I was able to get the keyboard to disappear when the enter key was pressed thanks to a thread here. I'm not having luck on the background touch resigning the first responder. The method is being entered, I have an NSLog in the method saying, "in backgroundTouched" but the keyboard is still there.
I've tried making the UIView a UIControl class so I could use the touch event.
journalComment is a UITextView.
-(IBAction)backgroundTouched:(id)sender
{
[journalComment resignFirstResponder];
NSLog(# "in backgroundTouched");
}
I've also tried having a invisible button under everything that calles the backGroundTouched method. I think it maybe that I'm missing something in interface builder, but I'm not sure what.
Thank you for any help!
This is what works for the done button:
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range
replacementText:(NSString *)text
{
// Any new character added is passed in as the "text" parameter
if ([text isEqualToString:#"\n"]) {
// Be sure to test for equality using the "isEqualToString" message
[textView resignFirstResponder];
// Return FALSE so that the final '\n' character doesn't get added
return FALSE;
}
// For any other character return TRUE so that the text gets added to the view
return TRUE;
}
I found the following code works best with my text view (not text field) without the delegate methods:
first you set up a tap gesture recognizer onto your view :
- (void)viewDidLoad{
UITapGestureRecognizer* tapRecognizer = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:#selector(tap:)];
tapRecognizer.delegate = self;
[self.view addGestureRecognizer:tapRecognizer];
}
and then in your tap method :
- (void)tap:(id)sender
{
// use to make the view or any subview that is the first responder resign (optionally force)
[[self view] endEditing:YES];
}
this should allow your keyboard to be dismissed when you anywhere on the view.
Hope this helps
Try this. We had this problem eariler, but eventually found the right solution.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[yourtextfield resignFirstResponder];
// you can have multiple textfields here
}
This should resolve the problem with the keyboard not dissapearing when pushing the background.