1:如何给一个Button增加一个可以传递的参数,代码如下:
实现的原理是使用了iOS的“黑魔法” Runtime
UIButton *surebtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
objc_setAssociatedObject(surebtn, "firstObject", backView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
objc_setAssociatedObject(surebtn, "callBack", backBlack, OBJC_ASSOCIATION_COPY_NONATOMIC);
然后在btn的事件响应方法里接受该参数
-(void)sureBtnAction:(UIButton*)button{
UIView *bakView = objc_getAssociatedObject(button, "firstObject");
SureBtnCallBack sucreback = objc_getAssociatedObject(button, "callBack");
sucreback();
[bakView removeFromSuperview];
}
note:注意在使用runtime时候要导入头文件
调试某段代码使用时间:
double start = CFAbsoluteTimeGetCurrent();
NSLog(@"duration---%f", CFAbsoluteTimeGetCurrent() - start);
import <objc/runtime.h>
CodeSign /Users/jiaguoshang/Library/Developer/Xcode/DerivedData/OutdoorClub-faehbxlmjdryajcjmcwmlhrlxyfa/Build/Products/Debug-iphonesimulator/OutdoorClub.app cd /Users/jiaguoshang/Desktop/OutdoorClub-2017-4-24-GoogleMaps export CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate export PATH=”/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin”
Signing Identity: “-“
/usr/bin/codesign --force --sign - --timestamp=none /Users/jiaguoshang/Library/Developer/Xcode/DerivedData/OutdoorClub-faehbxlmjdryajcjmcwmlhrlxyfa/Build/Products/Debug-iphonesimulator/OutdoorClub.app
/Users/jiaguoshang/Library/Developer/Xcode/DerivedData/OutdoorClub-faehbxlmjdryajcjmcwmlhrlxyfa/Build/Products/Debug-iphonesimulator/OutdoorClub.app: replacing existing signature /Users/jiaguoshang/Library/Developer/Xcode/DerivedData/OutdoorClub-faehbxlmjdryajcjmcwmlhrlxyfa/Build/Products/Debug-iphonesimulator/OutdoorClub.app: resource fork, Finder information, or similar detritus not allowed Command /usr/bin/codesign failed with exit code 1
这个错误的解决办法
cd ~/Library/Developer/Xcode/DerivedData/
然后再终端输入:xattr -rc .
终端翻墙打开 setproxy
终端关闭:unsetproxy
验证状态 curl -v getip.91jinrong.com
/** 手指触目开发 */
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
NSLog(@"😁😝 = %@",NSStringFromSelector(_cmd));
}
/** 手指将要离开 */
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{
NSLog(@"😁😝 = %@",NSStringFromSelector(_cmd));
}
/** 手指已经完全离开 */
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
NSLog(@"😁😝 = %@",NSStringFromSelector(_cmd));
}
/** 手指离开后开始减速 */
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
NSLog(@"😁😝 = %@",NSStringFromSelector(_cmd));
}
/** 滑动停止时候触发 */
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
NSLog(@"😁😝 = %@",NSStringFromSelector(_cmd));
}
image.png
4120931-340344bca6ffd874.png
网友评论