iOS UICollectionViewCell 点击事件自动化埋点

iOS 中经常要进行埋点,我们这里支持 UICollectionViewCell. 进行自动化埋点,思路:

通过hook UICollectionViewCell 的setSelected:方法,

则新的方法中执行埋点逻辑,并调用原来的方法

直接上代码

复制代码
@implementation UICollectionViewCell (LB)

+ (void)load
{
    instanceMethodExchangeImplementations([self class], @selector(setSelected:), [self class], @selector(setSelectedWithFilter:));
}

-(void)setSelectedWithFilter:(BOOL)selected
{
    // 过滤拼音键盘提示词
    if (selected && !self.skipTrack ) {
        UIView *tempSuperView = self.superview;
        while (tempSuperView) {
            if ([tempSuperView isKindOfClass:[UICollectionView class]]) {
                break;
            }
            tempSuperView = tempSuperView.superview;
        }
        // 非LBScrllView的cell,才由setSelected触发点击采集,LB cell由didSelected触发,
        if (tempSuperView && [tempSuperView isKindOfClass:[UICollectionView class]]
            && ![tempSuperView isKindOfClass:[LBCollectionView class]] && ![tempSuperView isKindOfClass:[LBScrollView class]]) {
            UICollectionView *collectionView = (UICollectionView *)tempSuperView;
            if (![collectionView isDragging] && ![collectionView isTracking] && ![collectionView isDecelerating]) {
                [self setMonitorSelected:selected];
            }
        }
    }
    [self setSelectedWithFilter:selected];
}


- (void)setMonitorSelected:(BOOL)selected
{
    if (selected && !self.skipTrack) {
     //执行埋点逻辑
   }
}

- (void)logClickCell
{
 
}

@end
相关推荐
点金石游戏出海1 小时前
每周资讯 | Krafton斥资750亿日元收购日本动画公司ADK;《崩坏:星穹铁道》新版本首日登顶iOS畅销榜
游戏·ios·业界资讯·apple·崩坏星穹铁道
90后的晨仔3 小时前
Xcode16报错: SDK does not contain 'libarclite' at the path '/Applicati
ios
finger244804 小时前
谈一谈iOS线程管理
ios·objective-c
Digitally4 小时前
如何将大型视频文件从 iPhone 传输到 PC
ios·iphone
梅名智5 小时前
IOS 蓝牙连接
macos·ios·cocoa
美狐美颜sdk12 小时前
跨平台直播美颜SDK集成实录:Android/iOS如何适配贴纸功能
android·人工智能·ios·架构·音视频·美颜sdk·第三方美颜sdk
Hacker_Oldv13 小时前
软件测试(功能、工具、接口、性能、自动化、测开)详解
运维·自动化
Java樱木13 小时前
使用字节Trae + MCP,UI 到网页自动化。
运维·自动化
恋猫de小郭17 小时前
Meta 宣布加入 Kotlin 基金会,将为 Kotlin 和 Android 生态提供全新支持
android·开发语言·ios·kotlin
泓博17 小时前
Objective-c把字符解析成字典
开发语言·ios·objective-c