In my app, to click a button will pop up a UIView, now I want to click anywhere outside of the UIView to dismiss the UIView.
I have tried adding a large transparent button under the UIView, invoke the button action to dismiss the UIView, but the button can't be expanded to Fullscreen because of the top navigationbar and bottom tabbar
Is any other way to achieve?
A giant UIButton it's not very good solution to your problem. You can simple use a UIGestureRecognizer for that.
You can allocate one like this:
UITapGestureRecognizer *tapImageRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(dismissPopUp)];
Then, just add the gesture to the views you want to respond to the selector chosen.
[self.view addGestureRecognizer:tapImageRecognizer];
and possibly others
[self.navBar addGestureRecognizer:tapImageRecognizer];
//etc
Just don't forget to implement the method used by the gesture recognizer
-(void)dismissPopUp
{
//your dimiss code here
}
Related
I have a UIButton and a UIView that animates, sliding down when the UIButton is pressed. The problem is that the UIView obscures the UIButton. I'd like the UIButton to always remain on top.
I tried this in the viewDidLoad:
[self.view bringSubviewToFront:categoryBtn];
doesn't work though.
thanks for any help
After Add any UIView or any other view on your this mainview , after that just add your this line for brings as a supeview for button
[self.view bringSubviewToFront:categoryBtn];
For Example on button action event you add any view then use code like bellow..
-(IBAction)yourButton_Clicked:(id)sender
{
///Add some code or view here and then after write this line here see bellow line
[self.view bringSubviewToFront:categoryBtn];
}
The other answer is will work, but this is exactly the kind of thing "insertSubview: belowSubview" was added for.
[self.view insertSubview:myNewView belowSubview:_categoryBtn];
This allows you to add the new view below the button on the view stack instead of adding it above the button and then rearranging the views.
I'm trying to implemet a scrollable Text view (not editable) that display some help information etc. and when the user is done with it all he has to do is tap it and it will disapear/hidden and the user will be back in the main screen.
The UITextview not reacting to tap event (or i'm not sure how to make it react to the tap event).
Any idea how to implement this ?
I also tried to put it inside a transparent button so i can capture the tap but then i cannot scroll the text view as it seem to be behinde the button.
i'm new to iphone , any help... gr8
Thanks
How about adding a tap gesture recognizer to the text view?
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(textViewTapped:)];
[yourTextView addGestureRecognizer:gestureRecognizer];
I'm beginner in Ipad development, so I'm trying to do an application that will have some of the twitter application features.
The issue is that I have a UIViewController which has the content. When you click on a image it should show a view that has a video in it, all above each others (as in twitter APP), the issue is that the view is appearing and it shows the subviews in it, but it dose not receive any touch event and doesn't get the background color.
So can you help me?
thanks :P
Make sure that the userInteraction is enabled for the image view. You can do it from the Interface builder, or alternatively, do -
myImageView.userInteractionEnabled = YES
You can then add gesture recognizer to that imageView- in your case a tap gesture recognizer. That should work. To add a gesture recognizer:
UITapGestureRecognizer *tapGestureRec = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTap:)];
[myImageView addGestureRecognizer:tapGestureRec];
Then handle the tap in the handleTap: method.
I have a tableView that is one of the views inside a pageControl. I want to be able to capture and respond to a sideways swipe gesture if it's within the tableView, and have the pageControl respond if it is outside of the tableView.
How can I do this?
As I see it, since swiping the table for an action and swiping the table to change pages is pretty much the same motion, you would just have to disable scrolling on the scrollview, scrollview.scrollEnabled = NO; and create a gesture recognizer for your table view, UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget: self action: #selector(myAction:)]; I haven't tested this code so please let me know if you run into any problems.
I have a UIButton set up and hooked up to an action in my view controller as usual. Just this by itself works fine.
Now, I have added the following to my view controller to set up a single tap:
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer * singleTapGesture = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:#selector(handleSingleTap:)];
[self.view addGestureRecognizer:singleTapGesture];
[singleTapGesture release]; }
Now, every time I tap the button it looks like it was tapped but it fires the gesture recognizer code instead of the button action.
How can I make it so that the button works when I tap the button and the tap gesture works when I tap anywhere else in the view?
Your problem is similar to this question which hopefully has been answered ;)
UIButton inside a view that has a UITapGestureRecognizer
Here is a simple solution
singleTapGesture.cancelsTouchesInView = NO;
Andrew,
It seems to me that you want to call a function when the user taps any where except the UI objects.
so my suggestion is that create a custom button of the size of screen(320x460 assuming that the grey bar is shown) place it back of all the objects in the IB. By this time you will be able to see a UIButton with almost 0% opacity.
and from the IB drag the selector option of the custom button to the file owners and select the function that you want to call and you are all done.
Its simpler than what you were attempting in your code