NSString drawInRect设置上下文 [英] NSString drawInRect set context

查看:67
本文介绍了NSString drawInRect设置上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在背景上绘制了一些图像。有时我的应用程序因奇怪的错误而崩溃:

I draw some image in background. Sometimes my app crashes with strange error:


功能签名专门化< Arg [0] =属于MyApp。

function signature specialization < Arg[0] = Owned To Guaranteed> of MyApp.

我检查了所有崩溃,并通过不使用上下文的方法获得了所有崩溃。其中之一绘制文本。

I checked all crashes, and I get all of them on methods that do not use context. One of them draw text. How can I specify context to draw text?

UIGraphicsBeginImageContextWithOptions(size, false, 1.0)
let ctx = UIGraphicsGetCurrentContext()
// some code
str.drawInRect(CGRectMake(floor(10 * scaleFactor), yOffset, size.width, floor(60 * scaleFactor)), withAttributes: textFontAttributes)
// code
let img = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()



编辑



我没有找到在特定上下文中绘制文本的任何方法。我在绘制文本之前使用 UIGraphicsPushContext(ctx),在绘制文本后使用 UIGraphicsPopContext() https://stackoverflow.com/a/10402637/820795

Edit

I do not found any method to draw text in specific context. I use UIGraphicsPushContext(ctx) before draw text and UIGraphicsPopContext() after. https://stackoverflow.com/a/10402637/820795

推荐答案

我不认为这与绘图有关。当Swift API中有一个错误时, Objective-C需要将nil参数值传递给Swift,但此参数的Swift版本未键入Optional,就会出现函数签名专门化。

I'm not convinced that this has anything to do with drawing. The "function signature specialization" arises when there's a mistake in the Swift APIs where Objective-C needs to pass a nil parameter value to Swift, but the Swift version of this parameter is not typed as an Optional.

这篇关于NSString drawInRect设置上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆