Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.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
Iphone 可可触摸:如何将触摸传递给另一个对象_Iphone_Objective C_Cocoa Touch_Uiview - Fatal编程技术网

Iphone 可可触摸:如何将触摸传递给另一个对象

Iphone 可可触摸:如何将触摸传递给另一个对象,iphone,objective-c,cocoa-touch,uiview,Iphone,Objective C,Cocoa Touch,Uiview,恐怕这是个初学者的问题: 我有一个覆盖整个屏幕的UIText。我在这个UITextView上有另一个透明视图,以便能够识别滑动手势(水平和垂直),如: - (void)viewDidLoad { [super viewDidLoad]; // UITextView CGRect aFrame = CGRectMake(0, 0, 320, 480); aTextView = [[UITextView alloc] initWithFrame:aFrame

恐怕这是个初学者的问题:

我有一个覆盖整个屏幕的UIText。我在这个UITextView上有另一个透明视图,以便能够识别滑动手势(水平和垂直),如:

    - (void)viewDidLoad
{
    [super viewDidLoad];

    // UITextView
    CGRect aFrame = CGRectMake(0, 0, 320, 480);
    aTextView = [[UITextView alloc] initWithFrame:aFrame];
    aTextView.text = @"Some sample text.";
    [self.view addSubview:aTextView];

    // canTouchMe
    CGRect canTouchMeFrame = CGRectMake(0, 0, 320, 480); 
    canTouchMe = [[UIView alloc] initWithFrame:canTouchMeFrame];
    [self.view addSubview:canTouchMe];
    }

让我们考虑用户触摸(不浏览)CouououCME视图。在这种情况下,我希望canTouchMe视图消失,并将触摸传递到隐藏在下面的UITextView,以便它进入编辑模式并启用UITextView具有的“自然”滚动选项(即仅水平)

我的方法如下所示:

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    [super touchesBegan:touches withEvent:event];

    UITouch *touch =[touches anyObject];
    gestureStartPoint = [touch locationInView:self.view];
}
我如何告诉此方法,如果它只识别一次触摸,它应该隐藏canTouchMeFrame并将触摸传递给UITextView

对不起,如果这是基本的,但我不知道如何实现这一点。谢谢你的建议


编辑:

我介绍了一种触碰结束的方法,但我仍然没有运气。触摸将不会转发到UITextView。我需要点击两次才能编辑它:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{

[super touchesMoved:touches withEvent:event];

UITouch *touch = [touches anyObject];
CGPoint currentPosition = [touch locationInView:self.view];

CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x); // will always be positive
CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y); // will always be positive


if (deltaY == 0 && deltaX == 0) {

    label.text = @"Touch"; [self performSelector:@selector(eraseText) withObject:nil afterDelay:2];

    [aTextView touchesBegan:touches withEvent:event];

    [self.view bringSubviewToFront:aTextView];
    [self.view bringSubviewToFront:doneEdit];


}

}
NSSet
有一个
-count
方法。如果
触摸
只有一个对象,则您只对一次触摸做出响应

 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    [super touchesBegan:touches withEvent:event];
    if ([touches count] == 1) {
       [self  hideMyRectangle];
       [someOtherObject touchesBegan:touches withEvent:event];
       //etc, etc.
       return;
       }
    // if you get here, there's more than one touch.       
    UITouch *touch =[touches anyObject];
    gestureStartPoint = [touch locationInView:self.view];
}

非常感谢你的帮助。这一切正常——唯一的问题是,我的程序现在只能检测触摸,不能再刷了。我相应地更新了代码(见上文)。看起来,如果我得到了不止一次的触摸,它不会识别出它是这样的,而只是一次触摸。例如,如果我刷卡,它只会将其识别为单触。