Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当用户触摸某个区域时调用方法的iOS_Ios_Methods_Uiview_Touch - Fatal编程技术网

当用户触摸某个区域时调用方法的iOS

当用户触摸某个区域时调用方法的iOS,ios,methods,uiview,touch,Ios,Methods,Uiview,Touch,所以我在键盘和对象之间有一个空间。我想在用户触摸这个特定区域时触发一个方法。我该怎么做呢? 我尝试过将UIView与UIApsignature一起使用,但似乎无法使其正常工作。您正在引用的“对象”是什么 如果它已经为用户交互启用,那么您所需要的就是 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { // do something } 将其放在视图控制器中。键盘将消耗触摸,因此不会触发。如果“对象”启用了

所以我在键盘和对象之间有一个空间。我想在用户触摸这个特定区域时触发一个方法。我该怎么做呢? 我尝试过将UIView与UIApsignature一起使用,但似乎无法使其正常工作。

您正在引用的“对象”是什么

如果它已经为用户交互启用,那么您所需要的就是

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    // do something
}
将其放在视图控制器中。键盘将消耗触摸,因此不会触发。如果“对象”启用了用户交互,它也将使用触摸。这只会在按下不消耗触碰的区域时触发

如果它不消耗触摸,那么

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    // get the touch
    UITouch *touch = [touches anyObject];

    // get the location of the touch in the main view of the view controller
    CGPoint touchPoint = [touch locationInView:self.view];

    // if the touch is inside the object then ignore it
    if (CGRectContainsPoint(object.frame, touchPoint)) {
        return;
    }

    // this is where you do something.
}

您可以使用不可见的按钮:

UIButton *theButton = [UIButton buttonWithType:UIButtonTypeCustom];
[theButton addTarget:self action:@selector(functionYouWantToCall:) forControlEvents:UIControlEventTouchUpInside];
theButton.frame = CGRectMake(x, y, width, height);
[self.view addSubview:theButton];

根据需要设置框架。完成按钮操作后,使用
[从SuperView中移除按钮]

在self.view中添加一个UITapSignature,但请确保将cancelsTouchInView的属性设置为“否”。这将防止您过度隐藏已在屏幕上放置的任何触摸方法

UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(someAction)];
tapGesture.cancelsTouchInView = NO;
[self.view addGestureRecognizer:tapGesture];

如果您正在尝试向键盘添加其他键,如Chrome如何设置“.com”的快捷键等,您可能需要尝试:

[self.yourTextView setInputAccessoryView:toolBar];

该对象是自定义TableViewCell中的UITextField。如果你能想象一个位于顶部的单元格和键盘之间的空间。当我在该空间中单击时,它会选择另一个单元格,这会导致图形故障和bug。所以我希望能一起解决这个问题。看起来可能会奏效。问题是,我不熟悉CGRectMake的参数。我知道(0,0)位于iOS屏幕的左上角。但宽度和高度……对我来说是灰色地带。那么宽度,是坐标/原点的+/-吗?或者它只是单向的?x和y标记矩形的原点,即左上角。从该原点测量宽度和高度;它们总是正整数。