我创建了 UIScrollView 的子类来实现我的一个自定义控件,此时一切工作正常。
但是,我希望能够在检测到 Touch Up Inside 事件时调用方法(就像界面生成器一样),有人知道我该怎么做吗?
最佳答案
因为 UIScrollView
不是从 UIControl
继承的,所以这是不可能的。不过,您可以通过在自定义 UIScrollView
类中实现 UIResponder
方法来中继 ScrollView 的触摸事件:
-(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];
}
关于iphone - 如何在自定义 View 中检测内部修饰?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4218486/