I am making use of a Presentation: Form Sheet in my app. So my ViewController gets displayed as a form with the black semi-transparent overlay around it.
I have implemented the logic to dismiss everything should the user tap anywhere outside my form sheet ViewController.
I would like to test this behavior but I'm not sure how to simulate the tap. How can I set an accessibility label to simulate this tap with a UI test?
Or any other suggestions how I can test this behavior?
Thanks!
You just want to click anywhere on the screen to dismiss everything?
[tester tapScreenAtPoint:CGPoint];
does that for you.
Most stuff about KIF is explained here:
http://www.raywenderlich.com/61419/ios-ui-testing-with-kif
Hi you can use UITapGestureRecognizer like this :
First create an instance of UITapGestureRecognizer
UITapGestureRecognizer *tapGesture = tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(someMethod:)];
Then attach this gesture recognizer to your view (i.e, black overlay you're talking about )
[self.view addGestureRecognizer:tapGesture];
Then implement someMethod: which is the method (action) that gets called when your formsheet is tapped
-(void)someMethod
{
//Logic to dismiss your formsheet
}
HTH :D
Related
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 :)
I have added functionality when keyboard appears we will up cause keyboard hides most part of ipad, but when view is up no touch event works, main motive to dismiss keyboards when tap or touch outside
below is screenshots shows I can't touch outside I have to use done button
You will need to create a UITapGestureRecognizer!
First of all define a UITapGestureRecognizer in your header (.h) file.
Then in the viewDidLoad:
tapGesture =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:#selector(closeKeyBoard)];
[self.view addGestureRecognizer:tapGesture];
Now the method which closes the keyboard:
-(void)closeKeyBoard {
[self.view endEditing:YES];
}
That's all you need!
Cheers
So, I'd like to receive touches from the status bar anywhere, any view, from the app. Well actually only specific views, like home screens and root view controllers say from a view of a tab view controller.
So my goal is to: hold down the status bar to dismiss the current view, like a back button.
The reason why I'm using this approach as a back button is because the app I am making is a utility, like fully functional apps within one app. Therefore I do not want to use up space on the navbar item to display a back button.
Other fissures would be nice, like swipe left/right or double tap, but mostly holding down. I've seen alternatives like using a UIScrollView and use the - scrollsToTop method. Hmm not what I am looking for.
Hope this can help you.
When you tap the top area, which has 44 height, the event would be triggered.
- (void)viewDidLoad{
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(navigationBack:)];
[self.view addGestureRecognizer:tapGesture];
}
- (void)navigationBack:(UITapGestureRecognizer *)tapGesture {
CGPoint p = [tapGesture locationInView:self.view];
if (CGRectContainsPoint(CGRectMake(0, 0, self.view.frame.size.width, 44), p)) {
NSLog(#"this where you put you navigation back event");
}
}
I have a scrollview with uiimageview1 added on it. On click on that uiimageview1 I want to present a viewcontroller to make some drawing. After drawing, I want to take picture of that drawing and place it on uiimageview1.
i don't know how to and where do i present that viewcontroller for drawing.
please help.
So, first you need to detect touches on your imageView. To do that you need to use UIGestureRecognizer or UIButton.
Then, you need to present a new view controller using the presentViewController:animated:completion: method of your current UIViewController (passing it the 'drawing' view controller).
After the drawing is performed, you can use iOS delegation pattern to notify the original view controller that you just drew something.
The original view controller handles that 'delegated event' and updates the image view accordingly.
UIViewController and UIButton documentations are here for you.
Create a UIButton with uiimageview.layer.bounds and add it as subview to uiimageview
Make the button background color [UIColor clearColor]
Add a #selector to button and push newViewController with segue or add it programaticaly from UINavigation Controller stack.
Otherwise you can make a pan gesture recognizer to UIImageView and listen for user interaction TAP on screen for pushing the new view controller
You can Simply do this by adding UITapGestureRecognizer properties to your image view.
Like:
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(presentViewController)];
[self.yourImageView addGestureRecognizer:tapGesture];
-(void)presentViewController{
// do remain stuff
}
Happy Codding :)
In a View Controller I'm building a grid of icons.
Each icon opens the same pop-up view , but filled in with different information.
I'm creating the grid in this way:
for (int i=0; i<NUM_BADGES; i++) {
BadgeThumbView *thumb = [[BadgeThumbView alloc] initWithFrame:CGRectMake(posX, posY, 70, 100)
andWithLabel:[NSString stringWithFormat:#"BADGE NAME N. %d", i]];
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(onBadgeTapped:)];
[thumb addGestureRecognizer:gestureRecognizer];
[thumb setTag:i];
[more code here....]
}
And in onBadgeTapped method I'm creating the pop up.
Now my problem is that everything works fine, but I just realized that when the pop up is opened, while interacting with its buttons I'm still triggering the gesture recognizer in the underlying view controller.
Is there a way to disable all GestureRecognizers in underlying view? Is my strategy wrong? And: is there a way to use a single UIGestureRecognizer for all my icons, in order to disable/enable in a easier way?
Thanks a lot
You can remove the recognizer from view or set userInteractionEnabled to temporarily disable it. Depending on how your popup is implemented, you may be able to disable them all at once.
One solution would to be adding thumbs as a subview of a container UIView, and adding that container to your parent view. You could then enable/disable all by setting userInteractionEnabled on the container view.
I think you should do some thing like disabling the userInteraction for all thumb views when the popup is appearing and re-enabling when disappearing like this
[[yourSuperView subviews]makeObjectsPerformSelector:#selector(setUserInteractionEnabled:) withObject:[NSNumber numberWithBool:FALSE]];
Else add all thumbViews to one subview( say 'b') then add view 'b' to superview(say 'a') as subView and turn off the user interaction to view b when popup appeared and turn on when popup disappears