• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

所有 UIButtons 的全局 ios 触觉反馈

[复制链接]
菜鸟教程小白 发表于 2022-12-13 16:04:33 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

如何在我的应用程序中为每个 UIButton 的每个 touchupinside 事件应用触觉反馈,而无需为每个单独的按钮编写代码?我已经尝试创建一个 UIButton 类别并覆盖 - (BOOL)pointInsideCGPoint)point withEventUIEvent *)event 但这会弄乱我的一些 UIButton 操作,(我可能实现得很糟糕)

有人有什么建议吗?



Best Answer-推荐答案


在类别中覆盖提到@ChoungTran 的此类方法并不是一个好主意。如果您想自定义类别中的默认方法,最好在 swizzled method 中进行。 .

但是,我更喜欢创建一个从 UIButton 派生的自定义类,并在那里实现该逻辑,并在需要触觉的任何地方使用该按钮。


来自 Apple documentation :

Although the Objective-C language currently allows you to use a category to override methods the class inherits, or even methods declared in the class interface, you are strongly discouraged from doing so. A category is not a substitute for a subclass. There are several significant shortcomings to using a category to override methods:

When a category overrides an inherited method, the method in the category can, as usual, invoke the inherited implementation via a message to super. However, if a category overrides a method that exists in the category's class, there is no way to invoke the original implementation.

A category cannot reliably override methods declared in another category of the same class.

This issue is of particular significance because many of the Cocoa classes are implemented using categories. A framework-defined method you try to override may itself have been implemented in a category, and so which implementation takes precedence is not defined.

The very presence of some category methods may cause behavior changes across all frameworks. For example, if you override the windowWillClose: delegate method in a category on NSObject, all window delegates in your program then respond using the category method; the behavior of all your instances of NSWindow may change. Categories you add on a framework class may cause mysterious changes in behavior and lead to crashes.

关于所有 UIButtons 的全局 ios 触觉反馈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52666393/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap