突出显示 UIControl 子类

Highlighting a UIControl subclass(突出显示 UIControl 子类)
本文介绍了突出显示 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)

好吧,我通过 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).

使用 beginTrackingWithTouchendTrackingWithTouch 我无法识别唯一的 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 子类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
java.lang.IllegalStateException: SimpleTypeImpl should not be created for error type(异常:不应为错误类型创建SimpleTypeImpl)
Android IllegalArgumentException: The tag for fragment_XXX is invalid. Received: layout-sw600dp/fragment_XXX_0(Android IlLegalArgumentException:Fragment_XXX的标签无效。收到:Layout-sw600dp/Fragment_XXX_0)
iOS convert audio sample rate from 16 kHz to 8 kHz(IOS将音频采样率从16 kHz转换为8 kHz)
Enforcing an audio sampling rate in iOS(在iOS中强制音频采样率)
HTTPS request using volley(使用 volley 的 HTTPS 请求)