突出显示 UIControl 子类

2023-07-07移动开发问题
1

本文介绍了突出显示 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 子类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

Cocos2d - 如何检查不同层中对象之间的交集
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)...
2024-08-12 移动开发问题
8

突出显示朗读文本(在 iPhone 的故事书类型应用程序中)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))...
2024-08-12 移动开发问题
9

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

正确的 cocos2d 场景重启?
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)...
2024-08-12 移动开发问题
7

[ios.cocos2d+box2d]如何禁用自动旋转?
[ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)...
2024-08-12 移动开发问题
7