本人亲测有效!更多交流可以家魏鑫:lixiaowu1129,公重好:iOS过审汇总,一起探讨iOS技术!
问题一:
Xcode运行旧版本项目编译报以下错误:
ini
Showing All Messages Assertion failed: (aliasSectionNum == sectionNum && "alias and its target must be located in the same section"), function assignAliasAtomOffsetInSection, file Layout.cpp, line 3248.
解决办法:Build Settings -> Other Linker Flags 中添加 -ld64
问题二:UIGraphicsBeginImageContextWithOptions 方法崩溃(Crash)
objectivec
*** Assertion failure in void _UIGraphicsBeginImageContextWithOptions(CGSize, BOOL, CGFloat, BOOL)(), UIGraphics.m:410
解决办法:将下面代码替换
swift
UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.opaque, self.contentsScale);CGContextRef context = UIGraphicsGetCurrentContext();if (self.opaque) {CGSize size = self.bounds.size;size.width *= self.contentsScale;size.height *= self.contentsScale;CGContextSaveGState(context); {if (!self.backgroundColor || CGColorGetAlpha(self.backgroundColor) < 1) {CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height));CGContextFillPath(context);}if (self.backgroundColor) {CGContextSetFillColorWithColor(context, self.backgroundColor);CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height));CGContextFillPath(context);}} CGContextRestoreGState(context);}task.display(context, self.bounds.size, ^{return NO;});UIImage *image = UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();self.contents = (__bridge id)(image.CGImage);
替换为:
swift
UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init];format.opaque = self.opaque;format.scale = self.contentsScale;UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:self.bounds.size format:format];UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {CGContextRef context = rendererContext.CGContext;if (self.opaque) {CGSize size = self.bounds.size;size.width *= self.contentsScale;size.height *= self.contentsScale;CGContextSaveGState(context); {if (!self.backgroundColor || CGColorGetAlpha(self.backgroundColor) < 1) {CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height));CGContextFillPath(context);}if (self.backgroundColor) {CGContextSetFillColorWithColor(context, self.backgroundColor);CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height));CGContextFillPath(context);}} CGContextRestoreGState(context);}task.display(context, self.bounds.size, ^{return NO;});}];self.contents = (__bridge id)(image.CGImage);