屏幕上的Xcode,Touch Detect,而不是UIScrollView

时间:2014-09-02 04:33:27

标签: objective-c xcode uiscrollview uitouch

我已经完成了用于检测触摸事件的代码,当我想要检测位置时,它可以工作。问题是,当我进入“开始触摸”事件时,“位置X”是110.之后我在图像中间移动到底部,而不是移动到顶部,最后我放回到中间。 “当前位置X”(从“触摸移动”事件中获取)与“位置X”完全不匹配

样本图像1> 记录返回,在开始时,location.x = 110; currentlocation.x = 110;

样本图像2> 我开始移动图像后。 location.x = 110; currrentlocation.x = 130~150(移到底部,当我将图像保持在顶部时,数字会保持增加);

*样本图像3> 之后我将图像移到顶部。 location.x = 110; currentlocation.x = 120~140(移到顶部,当我在底部拿着图像时,数字会继续减少);

意味着现在我移动图像后永远无法制作“location.x”=“currentlocation.x”。

我假设因为我使用的帧是UIScrollView,所以它检测到Scrollview位置,而不是屏幕视图位置。所以任何人都可以告诉我如何解决这些错误?或者我在哪里弄错了?

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if (touches.count == 1)
    {
        UITouch *touch = [[event allTouches] anyObject];
        location = [touch locationInView:touch.view];
        self.touchCount = 0;
        [self addSubview:s_overlayContainer];
        [self.delegate cardChangeBackGround:self];
    }
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    if (touches.count == 1)
    {
        UITouch *touchcheck = [[event allTouches] anyObject];
        currentLocation = [touchcheck locationInView:touchcheck.view];
        int LzcurrentTopBottom = LzTopBottom;
        self.touchCount++;
        // location > current = next
        // location < current = previos
        if(self.touchCount > 2)
        {
            if(currentLocation.x < location.x)
            {
                LzTopBottom = 1;
            }
            else{
                LzTopBottom = 2;
            }
        }
        NSLog(@"Current >>> %f,%f",location.x,currentLocation.x);
        NSLog(@"Current >>> %d,%d",LzTopBottom,LzcurrentTopBottom);
}
}

enter image description here enter image description here enter image description here

0 个答案:

没有答案