Error: Use of unresolved identifier 'kCGBlendModeMultiply'

假如想象 提交于 2019-12-01 14:29:01

问题


I recently updated to Xcode 7, beta 3.

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

When I run my application, i get 3 errors:

Use of unresolved identifier 'kCGBlendModeMultiply'

Use of unresolved identifier 'kCGLineCapRound'

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).

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


回答1:


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:

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)


来源:https://stackoverflow.com/questions/31309521/error-use-of-unresolved-identifier-kcgblendmodemultiply

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!