错误:使用无法解析的标识符"kCGBlendModeMultiply" [英] Error: Use of unresolved identifier 'kCGBlendModeMultiply'

查看:171
本文介绍了错误:使用无法解析的标识符"kCGBlendModeMultiply"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近更新为Xcode 7(测试版3).

I recently updated to Xcode 7, beta 3.

我遇到了一些问题,我似乎找不到关于SO的任何问题.

And I've run into some issues, I can't seem to find any questions for on SO.

运行应用程序时,出现3个错误:

When I run my application, i get 3 errors:

使用未解析的标识符'kCGBlendModeMultiply'

Use of unresolved identifier 'kCGBlendModeMultiply'

使用未解析的标识符'kCGLineCapRound'

Use of unresolved identifier 'kCGLineCapRound'

使用未解析的标识符"kCGLineJoinMiter"

Use of unresolved identifier '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).

在发行说明中我没有看到有关这些内容被删除的任何内容?因此,我对执行该操作有些困惑.我当然尝试重写这些行,但是我使用的3件事不再显示为选项.如果它们刚在最新的Swift 2.0中消失了,我该怎么用呢?

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?

这是第一个错误的代码.

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! :)

推荐答案

这应该有效:

CGContextSetBlendMode(ctx, CGBlendMode.Multiply)

...甚至就是这个:

... or even just this:

CGContextSetBlendMode(ctx, .Multiply)

如果您在CGContextSetBlendMode上使用Ctrl-click,然后从其声明跳转(以相同的方式)跳转到CGBlendMode的声明,那么您将看到:

If you Ctrl-click on CGContextSetBlendMode and then from its declaration jump (in the same way) to declaration of CGBlendMode then you will see:

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)

这篇关于错误:使用无法解析的标识符"kCGBlendModeMultiply"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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