iphone - 如何在自定义 View 中检测内部修饰?

标签 iphone

我创建了 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/

相关文章:

iOS 应用程序 - 尝试从图库中获取 iOS 照片但出现错误

iPhone 长 plist

设备上的 iPhone 测试

iphone - NSString 到 NSDate 不适用于 iDevice

iphone - 像 FaceTime 一样将 2 个视频合并在一起

iphone - 使用 NSRegularExpression 匹配 HTML

iphone - 我们如何使用 CSS 开发原生 iPhone 应用程序?

iphone - UITextView 没有成为 iOS 7 中的第一响应者

iphone - 释放 Objective-C block 中的对象

iphone - Facebook 贴到墙上的对话框是空的