zoukankan      html  css  js  c++  java
  • 把UIGestureRecognizer 中的点击事件变成Block

    //
    //  UIGestureRecognizer+Block.h
    //  rrefwvenfo
    //
    //  Created by 张凯泽 on 16/4/11.
    //  Copyright © 2016年 rytong_zkz. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    typedef void(^NVMGertureBlock)(id gesture);
    @interface UIGestureRecognizer (Block)
    +(instancetype)nvm_gestureRecongnizerWithActionBlock:(NVMGertureBlock)Block;
    -(instancetype)initWithActionBlock:(NVMGertureBlock)Block;
    @end
    //
    //  UIGestureRecognizer+Block.m
    //  rrefwvenfo
    //
    //  Created by 张凯泽 on 16/4/11.
    //  Copyright © 2016年 rytong_zkz. All rights reserved.
    //
    #import <objc/message.h>
    #import "UIGestureRecognizer+Block.h"
    
    
    static const int target_key;
    @implementation UIGestureRecognizer (Block)
    +(instancetype)nvm_gestureRecongnizerWithActionBlock:(NVMGertureBlock)Block
    {
        return [[self alloc]initWithActionBlock:Block];
    }
    -(instancetype)initWithActionBlock:(NVMGertureBlock)Block
    {
        self = [self init];
        [self addActionBlock:Block];
        [self addTarget:self action:@selector(invoke:)];
        return self;
        
    }
    -(void)addActionBlock:(NVMGertureBlock)block
    {
        if (block) {
            objc_setAssociatedObject(self, &target_key, block, OBJC_ASSOCIATION_COPY_NONATOMIC);
        }
    }
    -(void)invoke:(id)sender
    {
        NVMGertureBlock block = objc_getAssociatedObject(self, &target_key);
        if (block) {
            block(sender);
        }
    }
    @end
  • 相关阅读:
    测试标准学习
    jmeter学习笔记(一)
    Python开篇
    Openstack平台配置云服务器qemu-guest-agent服务
    easyui中datagrid数据行不足时填补空白方法
    guava缓存
    create tablet test like
    cse注册中心与nacos注册中心
    vo转ao
    mysql es 双云 灰度测试 读多写少
  • 原文地址:https://www.cnblogs.com/zkzzkz/p/5377327.html
Copyright © 2011-2022 走看看