Latest 1.0.3
Homepage https://github.com/DuceShen/UIViewBlock
License MIT
Platforms ios 9.0, requires ARC
Authors

使用效果

使用前:

  • UIView添加事件
    
    -(void)xxx {  
    view.userInteractionEnabled = YES;  
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doSomething:)];  
    [view addGestureRecognizer:tapGesture];  
    }  

-(void)doSomething {

}

- UIButton添加事件
```Objective-C
-(void)xxx {  
    [btn addTarget:self action:@selector(doSomething:)forControlEvents:UIControlEventTouchUpInside];  
}  

-(void)doSomething {  
    ...  
}

使用后:

  • UIVIew添加事件
    -(void)xxx {  
    [view addTap:^(UITapGestureRecognizer *tap) {  
        ...  
    }];  
    }
  • UIButton添加事件
    -(void)xxx {  
    [btn addTap:^(UIButton *btn) {  
        ...  
    }];  
    }

    使用方法

    直接拖入工程,或用cocoaPod导入

    使用建议

    建议配合以下两个宏使用(借鉴自yykit),防止循环引用

ifndef weakify

if DEBUG

if __has_feature(objc_arc)

define weakify(object) autoreleasepool{} weak typeof_(object) weak####object = object;

else

define weakify(object) autoreleasepool{} block typeof_(object) block####object = object;

endif

else

if __has_feature(objc_arc)

define weakify(object) try{} @finally{} {} weak typeof_(object) weak####object = object;

else

define weakify(object) try{} @finally{} {} block typeof_(object) block####object = object;

endif

endif

endif

ifndef strongify

if DEBUG

if __has_feature(objc_arc)

define strongify(object) autoreleasepool{} typeof(object) object = weak##_##object;

else

define strongify(object) autoreleasepool{} typeof(object) object = block##_##object;

endif

else

if __has_feature(objc_arc)

define strongify(object) try{} @finally{} typeof(object) object = weak##_##object;

else

define strongify(object) try{} @finally{} typeof(object) object = block##_##object;

endif

endif

endif

宏可放入.pch或Global.h等文件, 并且宏配合xcode自动完成效果更佳。
宏搭配使用效果:

-(void)xxx {  
    @weakify(self)  
    [btn addTap:^(UIButton *btn) {  
        @strongify(self)  
        ...  
    }];  
} 

Latest podspec

{
    "name": "UIViewBlock",
    "version": "1.0.3",
    "platforms": {
        "ios": "9.0"
    },
    "summary": "Categorys of UIView, UIButton.",
    "description": "u7ed9UIViewuff0cUIButtonu5404u589eu52a0u4e86u4e00u4e2au5e26blocku7684u65b9u6cd5uff0cu4fbfu4e8eu6dfbu52a0u70b9u51fbu4e8bu4ef6u3002",
    "homepage": "https://github.com/DuceShen/UIViewBlock",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "DuceShen": "[email protected]"
    },
    "source": {
        "git": "https://github.com/DuceShen/UIViewBlock.git",
        "tag": "v1.0.3"
    },
    "source_files": "UIViewBlock/*.{h,m}",
    "requires_arc": true
}

Pin It on Pinterest

Share This