iOS SWRevealViewController how to hide the left part programatically - ios

I included SWRevealViewController objective-c library with my swift project,
it's working fine,
my question is that i want to hide that left menu programtically when the user clicks on an empty space inside its table view.
i didn't know how, could you help please

If you want to hide the left menu programmatically just call the method
- (IBAction)revealToggle:(id)sender;
which is in SWRevealViewController.m class
If you want to capture the click on tableView's area where there are no cells, you can follow SunburstEnzo's advice.
Add a UITapUITapGestureRecognizer on the viewDidLoad method of the class with the tableView.
UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tableviewTapped)];
tapGesture.numberOfTapsRequired = 1;
[tapGesture setCancelsTouchesInView:NO]; //really important
[self.tableView addGestureRecognizer:tapGesture];
- (void) tapped
{
[self.revealViewController revealToggle:nil];
}

Related

How to implement common tap Gesture which will work for all View controllers

i want to use one common tap gesture for show/hide slider view in view controller with multiple View controller classes.
please provide solution how to implement this for ios .
slider view will show / hide by tap of view of View Controller.
and slider view contain tableview so tableview cell also be select when user click on tableview cell in ios.
is there any way to create a Abstract class for that.
thanks in advance.
You can add tapgesture to main content view of VC like,
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(handleTap:)];
self.view.userInteractionEnabled = YES;
[self.view addGestureRecognizer:recognizer];
And hanlde tap in method like,
-(void)handleTap : (UITapGestureRecognizer*)recognizer {
NSLog(#"tap detect");
}
Hope this will help :)

Implemented RWBlurPopover cant select value from tableview

I have integrated RWBlurPopover. I have added tableview inside Popover. Data is showing fine in tableview but when i am selecting any row didSelectRowAtIndexPath method is not calling.
I have implemented delegate and data source methods
I guess i can find code inside RWBlurpopover that is disabling touch on tableview.
Because all i am doing same as i have done in other Table View and it works file.
So RWBlurPopover, by default, dismisses on tap. To change that behaviour, you should go to RWBlurPopover.m and remove or comment out these lines:
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(dismiss)];
[self.popoverView.blurView addGestureRecognizer:tapGesture];

Using UITapGesture to dismiss a view controller but it selects cell buttons underneath, can I stop this from happening?

In my program I have a method to dismiss a UIView that pops up when I want to add a friend. I want this view to be dismissed when the used taps off the screen. This works however it also taps on any table cells underneath it and presses any buttons that are there. Code is below:
In my viewDidLoad:
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:#selector(dismissKeyboard)];
tap.cancelsTouchesInView = NO;
and:
-(void)dismissKeyboard {
[self.nameField removeFromSuperview];
[self.addFriendView removeFromSuperview];
}
Is there any way I can get around this to stop elements under being selected?

Removing UIImageView if the user taps on any point outside the UIImageView

My app shows an UIView which contains four UIButtons, one of them removes the UIView, but I also need is to remove the UIView, including all containing buttons when the user taps outside it.
This is how I remove the UIView using a button action:
-(IBAction)closeSideTasks: (id)sender
{
UIView * backgroundView = (UIView *)[self.view viewWithTag:7];
[backgroundView removeFromSuperview];
}
Any help or advice is welcome.
MORE INFORMATION:
This is the scenario: there is a table view. If the user swipes from left to right on a row, then the UIView appears on the right side of the view. The UIView *newView is removed after tapping on each of the buttons inside it and executing each button action. But may be the user does not tap on any of the buttons, and the UIView remains on the view. Then, what I want to achieve is a way that the UIView *newView gets removed if the user taps anywhere outside it, to prevent that it remains always on the view...
Check out UITapGestureRecognizer.
Example:
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] init];
tapGesture.delegate = self;
tapGesture.numberOfTapsRequired = 1;
tapGesture.numberOfTouchesRequired = 1;
[tapGesture addTarget:self action:#selector(tapChangeImage)];
[self.profileImageView addGestureRecognizer:tapGesture];
Now add the action method:
#pragma tap gestures
-(void)tapChangeImage{
// Remove view from superview!
}
Put a large button, full screen, with no graphics, no text, and a clear background. Have its action also remove the background

Adding and removing dynamically generated buttons in xcode

This is a strange one.
I'm quite new to Xcode. I've been trying to make a simple app that adds new buttons when you single click on the button view and removes them when you double click.
Adding buttons is OK, but removing them is unreliable. I think it has something to do with the way I've written the code because it only seems to remove the most recently added button on double click and not the actual button I've clicked on.
My abridged .m Code is below:
- (void)viewDidLoad
{
- (void)handleSingleTap:(UITapGestureRecognizer *)tapper {
//adds the buttons and gives them a unique tag
ButtonCount = ButtonCount+1;
btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(0, 0, 150, 150);
btn.userInteractionEnabled = YES;
btn.tag=PuckCount;
//attaches double tap recognizer to button
UITapGestureRecognizer *doubleTapGestureRecognizer = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:#selector(handleDoubleTap:)];
[doubleTapGestureRecognizer setNumberOfTapsRequired:2];
[btn addGestureRecognizer:doubleTapGestureRecognizer];
//Add Tap Recognizer to pucks to create new buttons
UITapGestureRecognizer *singleTapGestureRecognizer = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:#selector(handleSingleTap:)];
[singleTapGestureRecognizer setNumberOfTapsRequired:1];
[singleTapGestureRecognizer requireGestureRecognizerToFail:doubleTapGestureRecognizer];
[btn addGestureRecognizer:singleTapGestureRecognizer];
UIImage *buttonImage = [UIImage imageNamed:#"puck2.png"];
[btn setImage:buttonImage forState:UIControlStateNormal];
[self.view addSubview:btn];
}
//handles what happens on a double tap - THIS IS WHERE I THINK THE PROBLEM IS.
- (void)handleDoubleTap:(UIGestureRecognizer *)doubletap{
PuckSelected = self.view.tag;
[[self.btn viewWithTag:PuckSelected] removeFromSuperview];
}
#end
If you are trying to remove the button that is being double tapped, then try this.
- (void) handleDoubleTap:(UIGestureRecognizer *) doubletap {
[doubletap.view removeFromSuperview];
}
The UIGestureRecognizer has the view attached to it. There is no need to retrieve it again. Plus your problem was that you were trying to retrive the view from self instead of doubletap
Your handleDoubleTap method doesn't make sense.
Do something like this ::
- (void)handleDoubleTap:(UIGestureRecognizer *)doubletap{
PuckSelected = doubletap.view.tag;
[[self.view viewWithTag:PuckSelected] removeFromSuperview];
}
And it will work fine
- (void)handleDoubleTap:(UIGestureRecognizer *)doubletap{
PuckSelected = self.view.tag;
[[self.btn viewWithTag:PuckSelected] removeFromSuperview];
}
According to the code above, the button that gets removed it the button that has the same tag as self.view. But you don't show how self.views tag gets set, so it's impossible for us to know why or how your code selects the button that will be removed.
Regardless, you're probably heading down the wrong road here. It looks like you might have buttons nested inside a button? Which is odd. Also, you're using gesture recognizers with UIButtons, which don't need it. They already respond to things like taps and double-taps via the target-action mechanism.
Generally speaking, controls (that is, objects that derive from UIControl) already handle touches, taps, and other simple interactions. You'd really only use gesture recognizers on UIViews that need to track swipes or pinches or the like.
There seem to be 2 problems with your code.
1. When you do a single tap you are adding a button at (0,0,150,150) so any new button that gets added will be on top of the previous button. Maybe I am seeing this because of your abridged code, but you may want to do something about that.
2. In the UITapgesturerecognizer it will give you the view(id) that was tapped. You should use that in your selector. Like:
doubletap.view.tag.

Resources