UITapGestureRecognizer Programmatically trigger a tap in my view
I think you have multiple options here:
May be the simplest would be to send a
push event action
to your view but i don't think that what you really want since you want to be able to choose where the tap action occurs.[yourView sendActionsForControlEvents: UIControlEventTouchUpInside];
You could use
UI automation tool
that is provided with XCode instruments. This blog explains well how to automate your UI tests with script then.There is this solution too that explain how to synthesize touch events on the iPhone but make sure you only use those for unit tests. This sounds more like a hack to me and I will consider this solution as the last resort if the two previous points doesn't fulfill your need.
How to trigger tap gesture recognizer of UIView programmatically
I solved this by creating fake touches. Triggering gesture was not possible as gestures does not expose its action and selector. But as I have UIView
on which I want to tap. I can create a fake touch on that UIView
. This fake touch will automatically trigger the tap gesture. This link was very helpful for this.
UITapGestureRecognizer not triggering on UIImageView created programmatically
i solved by applying gesture on view, instead of each image view separately.
[self.view addGestureRecognizer:tap];
and then in handler/selector guessTapObject
function, i used this
CGPoint tapLocation = [gesture locationInView:self.view]; // gives the tap coordinates
for (UIView * view in self.view.subviews) { // gives view by iterating on each subview
CGRect dropRect = [[[view layer] presentationLayer] frame]; // specific way of getting the frame with respect to its layer
if(CGRectContainsPoint(dropRect, tapLocation)){ // checks for tap in the boundaries of view frame
if (view.tag > 900) // my specific view
// done what i want to do with that specific one
// as i removed it from my superview
}
}
}
Related Topics
Swift How to Change Uialertcontroller's Title Color
How to Wait for a Function to End on iOS/Swift, Before Starting the Second One
Google Objective-C API 'Gtl' with Swift
Schedule Number of Local Notifications
Get Average Color of Uiimage in Swift
Is There a Practical Way to Compress Nsdata
Full Resolution Screenshots for iPhone 6 and 6+
iPhone Opengl Es 2.0 - Pixel Perfect Textures
Create Ssl Connection Using Certificate
A Server with the Specified Hostname Could Not Be Found
Ios11 Causing Cors Issues in All Mobile Browsers
How to Wait for Method That Has Completion Block (All on Main Thread)
Can't Import Embedded Framework with Xcode 6 Gm
Storyboard Instantiateviewcontrollerwithidentifier Not Setting Iboutlets