Iphone 以编程方式将触摸传递到UIScrollView以滚动

Iphone 以编程方式将触摸传递到UIScrollView以滚动,iphone,uiscrollview,Iphone,Uiscrollview,基本上,我试图让UIScrollView只在更高的角度上滚动。与现在一样,如果将手指水平移动10度,滚动视图将滚动。我想把温度提高到,比如说,30度 在阅读了一些文章之后,我确定了最好的方法是在scrollview的顶部放置一个子类UIView。如果顶部的UIView触碰超过30度,请将其向下传递到scrollview,否则不要 然而,我不知道如何通过触地。这是我现在的代码: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)e

基本上,我试图让UIScrollView只在更高的角度上滚动。与现在一样,如果将手指水平移动10度,滚动视图将滚动。我想把温度提高到,比如说,30度

在阅读了一些文章之后,我确定了最好的方法是在scrollview的顶部放置一个子类UIView。如果顶部的UIView触碰超过30度,请将其向下传递到scrollview,否则不要

然而,我不知道如何通过触地。这是我现在的代码:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"glass touch began");
    UITouch *touch = [touches anyObject];
    beginning_touch_point = [touch locationInView:nil];
    [scroll_view touchesBegan:touches withEvent:event];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"glass touch ended");
    UITouch *touch = [touches anyObject];
    CGPoint previous_point = beginning_touch_point;
    CGPoint current_point = [touch locationInView:nil];

    float x_change = fabs(previous_point.x - current_point.x);
    float y_change = fabs(previous_point.y - current_point.y);

    if(x_change > y_change)
    {
        if(previous_point.x - current_point.x < 0)
        {
            [(MyScheduleViewController *)schedule_controller didFlickLeft];
        }
        else
        {
            [(MyScheduleViewController *)schedule_controller didFlickRight];
        }

        [scroll_view touchesCancelled:touches withEvent:event];
    }
    else 
    {
        [scroll_view touchesEnded:touches withEvent:event];
    }
}
-(void)touchesbeated:(NSSet*)toucheevent:(UIEvent*)event{
NSLog(@“玻璃触摸开始”);
UITouch*touch=[触摸任何对象];
开始触摸点=[触摸位置查看:无];
[滚动查看触摸开始:触摸事件:事件];
}
-(void)touchesend:(NSSet*)toucheevent:(UIEvent*)event{
NSLog(@“玻璃触摸结束”);
UITouch*touch=[触摸任何对象];
CGPoint上一个点=开始接触点;
CGPoint current_point=[触摸位置查看:无];
浮动x_变化=fabs(上一个_点.x-当前_点.x);
浮动y_变化=fabs(上一个_点.y-当前_点.y);
如果(x_变化>y_变化)
{
if(上一个_点.x-当前_点.x<0)
{
[(MyScheduleViewController*)调度_控制器左];
}
其他的
{
[(MyScheduleViewController*)调度_控制器右];
}
[滚动查看触控取消:触控事件:事件];
}
其他的
{
[scroll_view touchesend:touchs with event:event];
}
}

我现在知道它正在检查45度,但这不是重要的事情。重要的是,触摸确实被正确地传递到我的滚动视图。我让它在ToucheSBegind和touchesended上做了一个NSLog(),这两个操作都正确。它只是没有滚动。我担心触摸开始和触摸结束不会导致滚动。有人知道我做错了什么吗?

我也试着做同样的事情,但没有成功。scrollView似乎不处理TouchsMoved/TouchsBegind,但它会处理一些其他事件,以了解用户想要滚动视图。 对我来说,解决方案是确定thetshift值并将其显式设置为scrollView内容偏移量。它看起来是这样的(我没有确切的源代码不,这段代码可能工作不正确):


你有没有试过让它起作用?我现在也有类似的问题。
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *touch = [touches anyObject];

    CGPoint curr = [touch locationInView: self];
    CGPoint offset = [scrollView contentOffset];

    [scrollView setContentOffset: CGPointMake(offset.x + (curr.x - prev.x), offset.y) animated:YES];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    prev = [[touches anyObject] previousLocationInView: self];
}