简体   繁体   English

如何在自定义视图中检测到内部的触摸?

[英]How can I detect a touch up inside in my custom view?

I've created a subclass of UIScrollView to implement a one of my custom controls, at this point everything is working great. 我已经创建了UIScrollView的子类来实现我的一个自定义控件,目前一切正常。

However what I'd like to be able to call a methods whenever a Touch Up Inside event is detected (just like interface builder) does anybody know how I could do this? 但是,只要检测到Touch Up Inside事件(就像界面生成器一样),我希望能够调用方法的人是否知道我该怎么做?

Because UIScrollView does not inherit from UIControl , this is not possible. 因为UIScrollView不能从UIControl继承,所以这是不可能的。 You can, however, relay the scroll view's touch events by implementing the UIResponder methods in your custom UIScrollView class: 但是,您可以通过在自定义UIScrollView类中实现UIResponder方法来中继滚动视图的触摸事件:

-(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];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用滚动视图检测触摸? - how can i detect a touch with a scroll view? 如何在自定义MKAnnotationView中检测触摸? IOS 7 - How can I detect touch in custom MKAnnotationView? ios7 如何检测 UIImageView 的触摸事件? - How can I detect the touch event of an UIImageView? 如何将IBAction方法连接到普通视图以进行修饰事件? - How can I hook up an IBAction method to a plain view for a touch up event? 如何在UIViews的深层次结构中检测UIImageView上的触摸事件? - How can I detect touch events on a UIImageView inside a deep hierarchy of UIViews? 我们如何在iPhone的Textview中检测触摸或单击事件 - How can we detect touch up or click events in textview in IPhone 如何检测UITableViewCell内部的触摸 - How to detect touch inside an UITableViewCell 在包含UIControls的视图中检测触地和触地 - Detect touch down & touch up in a view containing UIControls 如何以编程方式将UIView或UIImageView与“内部触摸”等事件相关联? - How can I programmatically link an UIView or UIImageView with an event like “touch up inside”? 如何检测动画子视图上的触摸? 还是单击动画的UIButton? - How can I detect a touch on an animated subview ? Or click an animated UIButton?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM