项目中遇到的问题-2:编译第三方静态库报错、查看静态库的类型、绘制圆形...

项目中遇到的问题-2:编译第三方静态库报错、查看静态库的类型、绘制圆形...

2023年7月14日发(作者:)

项⽬中遇到的问题-2:编译第三⽅静态库报错、查看静态库的类型、绘制圆形  这⼀周⽐较折腾,由于项⽬应⽤涉及到和其他产品线APP的互相通信,在⾼层领导英(yi)明(ta)神(hu)武(tu)的战略指导下,我开始了与其他组同事的联调之旅。这⼏天鄙司负责产品的上级同事莅临监⼯,对现在的情况⼜提出了⼀些改进,作为⼀名程序猿,我已经奉上我的双膝。。。  ⼀、集成公司其他组的.a静态库,报错:duplicate symbole for architectecture i386 XXX

  查了⼀下报错的地⽅,都是指⽰.a的库和⼯程⾥⾯某些.m⽂件冲突,正好同事提到之前有碰到过这种情况,鉴于两⽅⽂件都是需要的,所以想了个办法:把其中⼀⽅的⽂件加了个前缀,⽐如CnlogsXXX.a。尝试了⼀下,解决了⼀部分问题。为什么是⼀部分呢,因为:  除了集成进来的.a以外,原来的⼯程⾥⾯的某些.a竟然也冲突了    没办法,接着查吧,最后发现⽤的的某个.a确实有问题,之前为了适应业务要求,兼顾旧版本的APP所以保留了⼆者,那这次为什么⼜出问题了呢,因为这次集成其他的.a,傲娇的需要加上⼏个编译选项到other linker flag⾥⾯去,然后就暴露了问题。  最后请熟悉这块的同事将冲突的.a合并成了⼀份,删掉了多余的,这才编译通过,然后⼜上⽹查了查,基本上都是⼀下⼏种原因:  1. 某些.h⽂件⾥⾯引⽤了.m⽂件(这个虽然我没遇到,不过也算是⼀种排查的可能原因)  2. 某些.m⽂件中的变量或者⽅法与⼯程引⼊的.a重复;  3. 太多了,参考这个:stackoverflow  ⼆、关于静态库的类型查看  先说⼀下静态库⼀般分为模拟器版本和真机版本,各⾃对应不同的CPU结构;  在模拟器上,常见的ARCH有i386(32位 mac) X_64(64位 mac)在真机上,常见的ARCH有3个:armv7,armv7s,arm64armv7:对应iPhone4和iPhone4Sarmv7s:对应iPhone5和iPhone5C,还有早期的iPadarm64/armv8:对应iPhone5S和iPhone6系列,以及⽐较新的iPad,如iPad mini2,iPad AirOK,需要知道⼀个有⽤的命令,lipo ⽤来制作静态库,查看静态库类型等。lipo -info XXX.a  可以得到XXX.a是什么类型的库,⽀持哪⼏种CPU结构,可以看到是否是fat lib哈(关于制作静态库,后续专门在写⼀下,⼤家可以上⽹搜⼀下,教程⼀堆⼀堆的;制作的步骤我觉得倒是其次,关键是怎么封装好⼀个好⽤的库,设计暴露出合适的接⼝)三、绘制圆形  做这个是因为我司产品觉得APP上⾯有的图标不够圆。。。(其实就是直接使⽤的截图,在⼤屏或者细看的情况下顶部会有切边),所以想让我们的背景圆形⽤代码来绘制。不得不说,我司就是这么追求极致。。。  废话不多说,直接上代码(虽然我觉得真⼼没啥技术含量) 1 #import "CustomView.h" 2 #define radious 20.5 3 #define PointX 24.5 4 #define PointY 24.5 5

6 @implementation CustomView 7

8 -(void)drawRect:(CGRect)rect 9 {10 [self drawRoundRecWithPoint:CGPointMake(PointX, PointY) andRadius:radious andFillColor:_fillColor];11 }12

13 //确定圆:圆⼼坐标X/Y 半径 颜⾊14 -(void)drawRoundRecWithPoint:(CGPoint)Point andRadius:(CGFloat)radius andFillColor:(UIColor*)fillColor15 {16 // 1.获取上下⽂17 CGContextRef context = UIGraphicsGetCurrentContext();18 UIGraphicsPushContext(context);19

20 // 2.画圆21 CGContextSetFillColorWithColor(context, r);22 CGContextAddArc(context, Point.x, Point.y, radius, 0, 2*M_PI, 0);23 CGContextDrawPath(context, kCGPathFill);24

25 UIGraphicsPopContext();26 }27

28 @end  需要注意⼏个点:  1.绘制图形,步骤基本上是死的,都是先获取到上下⽂context对象,然后设置颜⾊,线的⼤⼩等,然后画图。但是在iOS7的模拟器上⾯,我⼀开始碰到了⼀个错误,描述的真是吓尿我了:  : CGContextDrawPath: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing toan overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.上⽹查原因,还是⽜X的stackoverflowI got this error in the drawInContext(..) method of my custom CALayer implementation. UIBezierPath tries to use the UIGraphicsGetCurrentContext() which is nil by default in a custom layer. The online documentation explains thisIf you are not using a UIView object to do your drawing, however, you must push a valid context onto the stack manually using the UIGraphicsPushContext 's the code that finally worked with my comments inline (Swift code, but the solution is the same regardless)override func drawInContext(ctx: CGContext!) {

var path = UIBezierPath() // 1. Make sure you push the CGContext that was first passed into you. UIGraphicsPushContext(ctx) Point(CGPoint(x: 0, y: 0)) eToPoint(CGPoint(x: 150, y: 150)) var lineColor = lor() oke() dth = 2 ( // 2. Pop the context after you are done. UIGraphicsPopContext()  2.实现的过程中,忽然想起来前⼏天在微博上看到VVeibo的实现分析,有⼀个图标也是看上去是圆形,但其实是⽅形图⽚加了⼀层圆形的遮罩。我也可以试试,于是在原来图⽚上加了个遮罩,但是。。。效果不甚理想啊,圆形似乎不是很圆。。很圆。。。  3.为了做到更好的通⽤和扩展,我定义了圆的填充颜⾊,半径和圆点的point都⽤宏定义,然后再drawRect⽅法⾥⾯调⽤,只需要传给被调⽅法具体的属性,就可以返回⼀个绘制好的填充圆。时刻牢记MJ⼤神教导:  定义接⼝,是要让别⼈⽤的爽。

  好的,今天就到这⾥。

  

发布者:admin,转转请注明出处:http://www.yc00.com/news/1689265427a226466.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信