突出显示UIControl子类 [英] Highlighting a UIControl subclass

查看:102
本文介绍了突出显示UIControl子类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



基本上我需要一个图像按钮,特别是一个自定义对象:

1)在点击时调用控制器的动作

2)封装自定义数据

3)由包装器视图自动移动(不相关)


basically I need an image button, specifically a custom object that:
1) calls a controller's action when tapped
2) encapsulates custom data
3) is automatically moved by wrapper view (not relevant)

好吧,我用<$的子类得到了所有这些c $ c> UIControl (因为不建议继承 UIButton ,并且子类化 UIImageView 会变得困难管理要点1)。
但现在突出它的正确方法是什么?
我想在以任何方式点击时突出显示控件(即使是简单的alpha瞬间减少)。

Well, I got all this with a subclass of UIControl (since subclassing UIButton is not recommended and subclassing UIImageView makes difficult to manage the point 1). But now what is the correct way to highlight it? I would like to highlight the control when tapped in any way (even a simple momentary reduction of alpha).

使用 beginTrackingWithTouch endTrackingWithTouch 我无法识别唯一的 UIControlEventTouchUpInside 事件。

With beginTrackingWithTouch and endTrackingWithTouch I can't recognize the only UIControlEventTouchUpInside event.

控制器中的视图动画?在我看来,这是一个粗略的解决方案

A view animation in the controller? It seems to me a rough solution

是否有一个简单而直接的解决方案?

Is there a simple and immediate solution?

谢谢:(

推荐答案

我认为UIControls会根据触摸事件自动正确设置其突出显示的属性。你需要的是覆盖 -setHighlighted:实现特定算法的方法:

I think UIControls automatically set their highlighted property correctly, based solely on touch events. What you need is to override -setHighlighted: method to implement a specific algorithm:

- (void) setHighlighted: (BOOL) highlighted {
    [super setHighlighted: highlighted];
    // Only as an example. Caution: looks like a disabled control
    self.alpha = highlighted ? 0.5f : 1.0f;
}

这篇关于突出显示UIControl子类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆