xcode 错误:使用未解析的标识符“kCGBlendModeMultiply”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31309521/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error: Use of unresolved identifier 'kCGBlendModeMultiply'
提问by MLyck
I recently updated to Xcode 7, beta 3.
我最近更新到 Xcode 7, beta 3。
And I've run into some issues, I can't seem to find any questions for on SO.
我遇到了一些问题,我似乎找不到关于 SO 的任何问题。
When I run my application, i get 3 errors:
当我运行我的应用程序时,我收到 3 个错误:
Use of unresolved identifier 'kCGBlendModeMultiply'
Use of unresolved identifier 'kCGLineCapRound'
Use of unresolved identifier 'kCGLineJoinMiter'
使用未解析的标识符“kCGBlendModeMultiply”
使用未解析的标识符“kCGLineCapRound”
使用未解析的标识符“kCGLineJoinMiter”
However the 2 latter ones, disappear, although I assume they will show up after the first one is fixed (hence why I included it in this question).
然而,后两个消失了,尽管我认为它们会在第一个修复后出现(因此我将它包含在这个问题中)。
I didn't see anything in the release notes about these being removed? So I'm a bit stuck at what to do. I tried rewriting the lines of course, but the 3 things I used don't show up as options anymore. In case that they are just gone in the latest Swift 2.0, what can I use instead?
我在发行说明中没有看到关于这些被删除的任何内容?所以我有点不知道该怎么做。我当然尝试重写这些行,但是我使用的 3 件事不再显示为选项。如果它们在最新的 Swift 2.0 中消失了,我可以用什么代替?
Here's the code for the first error.
这是第一个错误的代码。
func alpha(value:CGFloat)->UIImage
{
UIGraphicsBeginImageContextWithOptions(self.size, false, 0.0)
let ctx = UIGraphicsGetCurrentContext()
let area = CGRect(x: 0, y: 0, width: self.size.width, height: self.size.height)
CGContextScaleCTM(ctx, 1, -1);
CGContextTranslateCTM(ctx, 0, -area.size.height)
CGContextSetBlendMode(ctx, kCGBlendModeMultiply)
CGContextSetAlpha(ctx, value)
CGContextDrawImage(ctx, area, self.CGImage)
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage;
}
Here's the code for the 2 latter errors:
这是后两个错误的代码:
for layer in [ self.top, self.middle, self.bottom ] {
layer.fillColor = nil
layer.strokeColor = UIColor.whiteColor().CGColor
layer.lineWidth = 4
layer.miterLimit = 4
layer.lineCap = kCALineCapRound
layer.masksToBounds = true
let strokingPath = CGPathCreateCopyByStrokingPath(layer.path, nil, 4, kCGLineCapRound, kCGLineJoinMiter, 4)
layer.bounds = CGPathGetPathBoundingBox(strokingPath)
layer.actions = [
"strokeStart": NSNull(),
"strokeEnd": NSNull(),
"transform": NSNull()
]
self.layer.addSublayer(layer)
}
Any help would be greatly appreciated! :)
任何帮助将不胜感激!:)
回答by courteouselk
This should work:
这应该有效:
CGContextSetBlendMode(ctx, CGBlendMode.Multiply)
... or even just this:
......甚至只是这个:
CGContextSetBlendMode(ctx, .Multiply)
If you Ctrl-click
on CGContextSetBlendMode
and then from its declaration jump (in the same way) to declaration of CGBlendMode
then you will see:
如果你Ctrl-click
在CGContextSetBlendMode
,然后从它的声明跳跃(以同样的方式)来的声明CGBlendMode
,那么你将看到:
enum CGBlendMode : Int32 {
/* Available in Mac OS X 10.4 & later. */
case Normal
case Multiply
case Screen
case Overlay
// ...
}
Similarly, the other line that produces the error should be changed to:
同样,产生错误的另一行应更改为:
let strokingPath = CGPathCreateCopyByStrokingPath(layer.path, nil, 4, .Round, .Miter, 4)