如何在自定义视图中检测到内部修饰?

cgo*_*ain 2 iphone

我已经创建了一个UIScrollView的子类来实现我的一个自定义控件,此时一切都运行良好.

然而,每当检测到Touch Up Inside事件时,我希望能够调用方法(就像界面构建器一样)有人知道我该怎么做吗?

Eva*_*ski 5

因为UIScrollView不继承UIControl,所以这是不可能的.但是,您可以通过实现UIResponder自定义UIScrollView类中的方法来中继滚动视图的触摸事件:

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{   
    if (!self.dragging)
    {
        [self.nextResponder touchesEnded: touches withEvent:event]; 
    }       

    [super touchesEnded: touches withEvent: event];
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if (!self.dragging)
    {
        [self.nextResponder touchesBegan: touches withEvent:event]; 
    }       

    [super touchesBegan: touches withEvent: event];
}
Run Code Online (Sandbox Code Playgroud)