ibireme / yycategories Goto Github PK
View Code? Open in Web Editor NEWA set of useful categories for Foundation and UIKit.
License: MIT License
A set of useful categories for Foundation and UIKit.
License: MIT License
model返回的值不再有simulator了,用TARGET_OS_SIMULATOR来处理吧
- (BOOL)isSimulator {
static dispatch_once_t one;
static BOOL simu;
dispatch_once(&one, ^{
// No more working any more. Do it at build time.
// simu = NSNotFound != [[self model] rangeOfString:@"Simulator"].location;
#if TARGET_OS_SIMULATOR
simu = YES;
#else
simu = NO;
#endif
});
return simu;
}
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];
UIImage *image = [[UIImage imageNamed:@"1"] imageByInsetEdge:UIEdgeInsetsMake(0, 10, 0, 0) withColor:[UIColor redColor]];
[imageView setImage:image];
[self.view addSubview:imageView];
能看到图片被盖了, 但是是白色的, 并无红色啊。。。
在我的项目里面返回来不是 ip 地址 直接走的是ipv6, 我的手机上是ipv4的
NSDecimalNumber *a = [NSDecimalNumber decimalNumberWithString:[YPDataHandle shareHandle].stageDataModel.san];
NSDecimalNumber *b =[NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%d",100]];
NSDecimalNumberHandler * handler = [[NSDecimalNumberHandler alloc] initWithRoundingMode:NSRoundBankers scale:6 raiseOnExactness:NO raiseOnOverflow:NO raiseOnUnderflow:NO raiseOnDivideByZero:NO];
NSDecimalNumber *result = [[a decimalNumberByDividingBy:b] decimalNumberByRoundingAccordingToBehavior:handler];
NSString *numString = [NSString stringWithFormat:@"%.6lf",[result doubleValue]];
feiLv = [numString doubleValue];
numString 为@"0.01800" 但是转换成doubleValue之后精度出现了丢失 feiLv 为0.017999999999999999
无论我尝试用NSString转化为double 或者NSDecimalNumber转化为double 都会出现这个情况 因为做的一款货币类型的app 这样计算很不准确 请问yaoyuan大神有没有什么好的解决办法 ~~
首先感谢你分享这么多好用的东西,万分感谢!
其次就是咨询下这些分类中是否用到了系统私有api,导致无法通过审核?
多谢!
再次感谢你的分享~
经测试,imageByRotateRight90并不能有效的旋转头像,原因是imageByRotate函数的方向值调用的是self.orientaton,所以进去啥方向出来还是啥方向,已经验证
其中 Foundation 层面的完全相同,UIKit 层面的需要修改
iOS 8.1 8.3 8.4 越狱设备
Crash 在 UIDevice+YYAdd.m line 77
#ifndef YYSYNTH_DUMMY_CLASS
#define YYSYNTH_DUMMY_CLASS(_name_) \
@interface YYSYNTH_DUMMY_CLASS_ ## _name_ : NSObject @end \
@implementation YYSYNTH_DUMMY_CLASS_ ## _name_ @end
#endif
YYSYNTH_DUMMY_CLASS(NSString_YYAdd)
预编译后的内容:
@interface YYSYNTH_DUMMY_CLASS_NSString_YYAdd : NSObject @end
@implementation YYSYNTH_DUMMY_CLASS_NSString_YYAdd @end
这样可以防止在工程中的文件中加入-all_load``-force_load
这点原理,没搞明白,有相关的资料没?
http://developer.apple.com/library/mac/#qa/qa2006/qa1490.html
这个网址打开找不到.
If I were to create a pull request to eliminate these warnings, would you accept it?
they are ALL a result of method parameter definition comments being incorrect.
thanks!
你好~ 如标题描述,用贝塞尔曲线对UIImage切成圆形,生成的图片边缘有明显的锯齿,或者说毛刺,显得比较粗糙。如果在UIImageView中直接用layer.cornerRadius则比较顺滑,但是会对fps产生影响。 不知道这个问题是否有解决办法?
首先同为90年出生,好佩服作者。。。
今天用YYCategories,功能上面没的说给力好用,不过引入YYCategories后编译报错,还是我没见过的错误,查了半天也不知道怎么回事。后来仔细地找才发现是YYCategories中的方法名或者宏之类的与项目中的某些定义冲突了(因为项目比较老,所以还在用pch文件,我是直接把YYCategories放到pch文件里了)。总之就是觉得YYCategories的命名还是很容易导致冲突的,个人觉得把命名前面加上yy_前缀就不会有这些意外的事发生了,我能力平平,说的不对请忽略。
property cannot have array or function type 'BOOL (())' (aka 'bool ()')
static inline CGPoint CGRectGetCenter(CGRect rect) {
return CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect));
}
static declaration of 'CGRectGetCenter' follows non-static declaration
你好,我工程里报错,请问是什么原因?
有一些新设备和新系统兼容的问题。看来只能直接拖文件修改了。
@"Watch1,7" : @"Apple Watch Series 1 42mm",
Watch2,7 ?
修改后如下:
//引入头文件
#import "sys/utsname.h"
- (BOOL)isSimulator {
static dispatch_once_t one;
static BOOL simu;
dispatch_once(&one, ^{
struct utsname systemInfo;
uname(&systemInfo);
NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
simu = ([platform isEqualToString:@"i386"] || [platform isEqualToString:@"x86_64"]);
});
return simu;
}
测试环境模拟器 ios 9.2 (13C75), iPhone 6s Plus:
BOOL ok = [@"123456" containsEmoji];
竟然检测 ok 是 YES。
yy版本是:
pod 'YYCategories', '~> 0.9.3'
YYCGAffineTransformGetFromPoints编译warning什么时候能出个新版本?
- (NSInteger)yearForWeekOfYear {
return [[[NSCalendar currentCalendar] components:NSCalendarUnitYearForWeekOfYear fromDate:self] yearForWeekOfYear];
}
weekOfYear 我知道是一年有多少个星期,yearForWeekOfYear ,表示英文差,难以理解哦...
base64解码的时候没有剔除非base64编码字符的影响,比如空格、回车。导致解码错误。
Masonry 会定义该宏
If you want to use masonry without all those pesky 'mas_' prefixes. Add #define MAS_SHORTHAND to your prefix.pch before importing Masonry
如果引入YYCategories的话,省略了mas_的代码都会报错。。。。
你好,我在看你的demo中文件T1StatusCell中的T1StatusMediaView类的是够发现你在Block中是先对self进行weak处理 ,然后在block中进行strong处理,请问这样有什么好处吗,为什么不直接使用weakSelf呢?
另外,我看你在block中最后还是使用self,是因为你把self重新赋值了?这样做会有什么好处吗?
能帮我讲解下原因或者推荐一篇相关的文章学习一下吗?万分感谢! @ibireme
你好,我在使用UIControl+YYAdd这个分类的时候用到了addBlockForControlEvents:block函数,但是发现当block中引用control的时候编译器会有“block 循环引用”的警告。
按照我们正常的功能来说由于block是运行的时候加进去的,所以编译器应该是无法识别到的。
接着我试着在工程下执行grep "addBlockForControlEvents" * -Rn 命令来查找你是否做了什么设置,但是没有找到什么线索。
所以我想问一下,这个编译器提醒的功能是如何做到的。
if (target.events & controlEvents) {
UIControlEvents newEvent = target.events & (~controlEvents);
if (newEvent) {
[self removeTarget:target action:@selector(invoke:) forControlEvents:target.events];
target.events = newEvent;
[self addTarget:target action:@selector(invoke:) forControlEvents:target.events];
} else {
[self removeTarget:target action:@selector(invoke:) forControlEvents:target.events];
[removes addObject:target];
}
}
第一个if不是已经判断是不是同一个事件了么,第二行是什么意思
虽然可以通过
但是加上这个某些时候更方便些:
可以直接使用 RGB(11, 134, 123) 这样的形式了,
When targeting App Extension, UIApplication
is not available, which causes compilation error.
CGAffineTransform YYCGAffineTransformGetFromPoints(CGPoint before[3], CGPoint after[3]);
Array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)
shuffle 方法可不可以拿来从数组中取一定数量的随机内容? 先洗牌,再取前N个。这样取得的内容符不符合随机的要求?
NSArray *originArray = ......;
NSMutableArray *tmp = [NSMutableArray arrayWithArray:originArray];
[tmp shuffle];
NSUInteger count = 10;
NSArray *randomArray;
if (tmp.count >= count) {
randomArray = [tmp subarrayWithRange:NSMakeRange(0, count)];
}else{
randomArray = tmp;
}
给UIBarButtonItem添加了actionBlock不能回调
YES if swizzling succeed; otherwize, NO.
otherwize 应该是 otherwise 吧...
通过PDF文件路径获取:
UIImage *image = [UIImage imageWithPDF:[[NSBundle mainBundle] pathForResource:@"4.pdf" ofType:@""]];
会报错:
<Error>: CFURLCreateDataAndPropertiesFromResource: failed with error code -15.
Problem:
pdf = CGPDFDocumentCreateWithURL((__bridge CFURLRef)[NSURL URLWithString:dataOrPath]);
Fix:
pdf = CGPDFDocumentCreateWithURL((__bridge CFURLRef)[NSURL fileURLWithPath:dataOrPath]);
问题解决了飘过
#ifndef YYSYNTH_DYNAMIC_PROPERTY_CTYPE
#define YYSYNTH_DYNAMIC_PROPERTY_CTYPE(_getter_, _setter_, _type_) \
- (void)_setter_ : (_type_)object { \
[self willChangeValueForKey:@#_getter_]; \
NSValue *value = [NSValue value:&object withObjCType:@encode(_type_)]; \
objc_setAssociatedObject(self, _cmd, value, OBJC_ASSOCIATION_RETAIN); \
[self didChangeValueForKey:@#_getter_]; \
} \
- (type)_getter_ { \
_type_ cValue = { 0 }; \
NSValue *value = objc_getAssociatedObject(self, @selector(_setter_:)); \
[value getValue:&cValue]; \
return cValue; \
}
#endif
_getter_的返回值应该是_type_
代码没有问题,只是有个地方有点疑惑。以下是 UIGestureRecognizer+YYAdd 的源代码,我尝试注释了把 target 添加到数组的代码。按我的理解之所以加到数组是为了后续方便 remove,但是结果却是 target 出了这个作用域自动释放了,打印 gesture 实例发现 target 也是 nil 。奇怪,难道 addTarget:action
不会对 target 强制持有吗?求解惑。
- (void)addActionBlock:(void (^)(id sender))block {
_YYUIGestureRecognizerBlockTarget *target = [[_YYUIGestureRecognizerBlockTarget alloc] initWithBlock:block];
[self addTarget:target action:@selector(invoke:)];
// NSMutableArray *targets = [self _yy_allUIGestureRecognizerBlockTargets];
// [targets addObject:target];
}
使用performSelectorWithArgs获取返回的对象,会直接释放
在getReturnFromInv:withSig:方法里
case '@': { // id
id ret = nil;
[inv getReturnValue:&ret];
return ret;
};
如果在id前面加上__autoreleasing就没有问题了,但是不知道具体原因是什么
在NSString+YYAdd的.m文件中62行if (!regex) return; 是不是应该判断pattern?
Xcode: Xcode 8 Beta
iOS: iOS 10 Beta2
测试将187行:
NSAttributedString *str = [[NSAttributedString alloc] initWithString:emoji attributes:@{ (__bridge id)kCTFontAttributeName:(__bridge id)font, (__bridge id)kCTForegroundColorAttributeName:(__bridge id)[UIColor clearColor].CGColor }];
修改为
NSAttributedString *str = [[NSAttributedString alloc] initWithString:emoji attributes:@{ (__bridge id)kCTFontAttributeName:(__bridge id)font, (__bridge id)kCTForegroundColorAttributeName:(__bridge id)[UIColor blackColor].CGColor }];
即可。不知道为什么AttributedString字体颜色为clear就绘制不出来,大神解释下原因,修复下。
PS:发现iOS 10绘制图片的时候,图片透明部分都会绘制出一个阴影来,微博的link图标就是这样的。
UIView+YYAdd文件 frame那些熟悉能添加类前缀YY吗?因为我用的masonry布局可以设置它里面的宏定义然后布局的时候不用写mas_,我用left right那些的时候就会和UIView的类别冲突的
最新苹果审核中,不能包含 method_exchangeImplementations
还有些类包含了 respondsToSelector, performSelector
是否会删除相应的方法呢?
@"iPhone10,1" : @"iPhone 8",
@"iPhone10,4" : @"iPhone 8",
@"iPhone10,2" : @"iPhone 8 Plus",
@"iPhone10,5" : @"iPhone 8 Plus",
@"iPhone10,3" : @"iPhone X",
@"iPhone10,6" : @"iPhone X",
imageByRoundCornerRadius:(CGFloat)radius corners:(UIRectCorner)corners borderWidth:(CGFloat)borderWidth borderColor:(UIColor *)borderColor borderLineJoin
这个方法获取带border的图片偏小。
CGFloat strokeInset = (floor(borderWidth * self.scale) + 0.5) / self.scale;
这个strokeInset计算的不对吧,感觉应该是 floor(borderWidth / 2)
YYCategories 中NSString的Category URL编码存在问题
stringByURLEncode方法无法将 '+'号转换成%2b
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.