基本上我需要一个图像按钮,特别是一个自定义对象:
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)
好吧,我通过 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 子类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!