iOS Showing All Messages Assertion failed: (aliasSectionNum == sectionNum && "al

复制代码
本人亲测有效!更多交流可以家魏鑫: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);
相关推荐
大熊猫侯佩2 小时前
Swift 中更现代化的调试日志系统趣谈(一)
debug·swift·apple
大熊猫侯佩2 小时前
Swift 中更现代化的调试日志系统趣谈(二)
debug·swift·apple
90后的晨仔3 小时前
RxSwift 源码解析:深入 ObservableType 扩展与订阅机制
ios
90后的晨仔3 小时前
Swift 中的`@dynamicMemberLookup`是什么?
ios
90后的晨仔3 小时前
解析 RxSwift 的响应式基石
ios
90后的晨仔4 小时前
RxSwift 的DisposeBag中的SpinLock()分析
ios
90后的晨仔4 小时前
RxSwift 中的 DisposeBag解析
前端·ios
gavin carter4 小时前
iOS-SM3加密算法N种集成
ios·sm3
Swift社区14 小时前
Swift 解法详解:如何在二叉树中寻找最长连续序列
开发语言·ios·swift