[iOS]CoreGraph在64位模式下与NSString drawInRect冲突
来源:互联网 发布:知乎 环氧树脂固化剂 编辑:程序博客网 时间:2024/05/22 09:40
iOS SDK支持64bit后,大部分代码可以直接无缝转换并通过编译,但是这些代码在运行时可能会有所差异,所以开发时需要特别注意,Cocoa-Charts在开发过程中就发现了这类问题。
问题现象:
CoreGraph绘图方法与NSString的drawInRect方法在64Bit下存在着冲突,64Bit下调用drawInRect之后会导致CGContext中的path被清空从而使CGContextStrokePath不进行任何绘图操作,而32Bit下没有任何问题。
问题代码:
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 0.5f);
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
//代码省略
//在控件内绘制一条直线
CGContextMoveToPoint(context, 0.f, 0.f);
CGContextAddLineToPoint(context, 100.f, 100.f);
//在控件内显示指定的文本
NSString string = @“TEST”;
[string drawInRect:CGRectMake(0, 0, 100, 20)
withFont: [UIFont systemFontOfSize:14.f]
lineBreakMode:NSLineBreakByWordWrapping
alignment:NSTextAlignmentRight];
//代码省略
CGContextStrokePath(context);
CGContextFillPath(context);
解决办法:
将代码分割,将使用CoreGraph绘图方法的代码段与调用NSString的drawInRect方法的代码段分别书写。
修改后的代码:
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 0.5f);
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
//代码省略
//在控件内绘制一条直线
CGContextMoveToPoint(context, 0.f, 0.f);
CGContextAddLineToPoint(context, 100.f, 100.f);
//代码省略
CGContextStrokePath(context);
CGContextFillPath(context);
//在控件内显示指定的文本
NSString string = @“TEST”;
[string drawInRect:CGRectMake(0, 0, 100, 20)
withFont: [UIFont systemFontOfSize:14.f]
lineBreakMode:NSLineBreakByWordWrapping
alignment:NSTextAlignmentRight];
最后感谢BUG的发现者:
Marco Almeida(http://www.marcoios.com/MarcoiOS/index.html)
0 0
- [iOS]CoreGraph在64位模式下与NSString drawInRect冲突
- NSString的drawInRect: withAttributes:的参数解析
- iOS7下的drawInRect的新方法drawInRect:withAttributes:使用
- 如何在UEFI模式下安装64位win7系统
- IIS32位,64位模式下切换
- IIS32位,64位模式下切换
- IIS32位,64位模式下切换
- 如何在安装32位Oracle客户端组件的情况下以64位模式运行
- 如何在安装32位Oracle客户端组件的情况下以64位模式运行
- QT5.5与VS2013在64位环境下集成
- 位与运算在iOS中的使用
- Special Memory Leak For IOS---drawinrect
- iOS NSString 与NSData转化
- iOS NSString 与NSData转化
- UITableViewCell drawInRect 在iOS7中失败
- libtiff库在windows下的编译(32位与64位)
- 如果在安装32位oracle 客户端组件时的情况下以64位模式运行,将出现问题
- C# 如果在安装 32 位 Oracle 客户端组件的情况下以 64 位模式运行
- Random随机生成几位数字和UUID随机生成几位字母加数字组合
- 2014 ACM/ICPC Xi'an Regional I - International Collegiate Routing Contest
- [iOS]Makefile交叉编译静态库TA-lib
- [iOS]使用UIActivityViewController实现AirDrop功能
- [iOS]iPad和iPhone版本xib文件相互转换
- [iOS]CoreGraph在64位模式下与NSString drawInRect冲突
- [Android]使用Emma进行单体测试代码覆盖率分析
- [iOS]UILabel取消自动Trim空格和换行等空白字符
- [iOS]7.1使用OTA部署APP出现Cannot install applications错误
- [iOS]UIWebView禁止前进和后退
- svn之黄色感叹号处理方法
- [iOS]使用Dropbox的https外链OTA部署APP
- [Android]升级SDK tools后ant自动编译脚本错误
- [Android]使用android-junit-report.jar导出单元测试报告