编辑:更新让问题更明显
编辑2:使我的问题更准确地解决我现实世界的问题.我实际上正在寻找采取行动,如果他们点击任何地方EXCEPT在一个屏幕上的文本字段.因此,我不能简单地听文本框内的事件,我需要知道他们是否在视图中的任何地方轻拍.
我正在编写单元测试来声明当手势识别器在我的视图的某个坐标中识别出水龙头时,会采取某种措施.我想知道我是否可以通过编程方式创建将由UITapGestureRecognizer处理的触摸(特定坐标).我正在尝试在单元测试期间模拟用户交互.
UITapGestureRecognizer在Interface Builder中配置
//MYUIViewControllerSubclass.m -(IBAction)viewTapped:(UITapGestureRecognizer*)gesture { CGPoint tapPoint = [gesture locationInView:self.view]; if (!CGRectContainsPoint(self.textField,tapPoint)) { // Do stuff if they tapped anywhere outside the text field } } //MYUIViewControllerSubclassTests.m //What I'm trying to accomplish in my unit test: -(void)testThatTappingInNoteworthyAreaTriggeRSStuff { // Create fake gesture recognizer and ViewController MYUIViewControllerSubclass *vc = [[MYUIViewControlleRSSubclass alloc] init]; UITapGestureRecognizer *tgr = [[UITapGestureRecognizer initWithView: vc.view]; // What I want to do: [[ Simulate A Tap anywhere outside vc.textField ]] [[ Assert that "Stuff" occured ]] }