10

我最近更新到 Xcode 7,beta 3。

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

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

使用未解析的标识符“kCGBlendModeMultiply”

使用未解析的标识符“kCGLineCapRound”

使用未解析的标识符“kCGLineJoinMiter”

但是后两个消失了,尽管我认为它们会在第一个修复后出现(因此我将它包含在这个问题中)。

我在发行说明中没有看到任何关于这些被删除的内容?所以我有点不知道该怎么做。我当然尝试重写这些行,但我使用的 3 件事不再显示为选项。如果它们刚刚在最新的 Swift 2.0 中消失,我可以使用什么来代替?

这是第一个错误的代码。

    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;
}

这是后两个错误的代码:

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

任何帮助将不胜感激!:)

4

1 回答 1

18

这应该有效:

CGContextSetBlendMode(ctx, CGBlendMode.Multiply)

...甚至只是这样:

CGContextSetBlendMode(ctx, .Multiply)

如果您Ctrl-click继续CGContextSetBlendMode从其声明跳转(以相同方式)到声明,CGBlendMode那么您将看到:

enum CGBlendMode : Int32 {

    /* Available in Mac OS X 10.4 & later. */
    case Normal
    case Multiply
    case Screen
    case Overlay

    // ...
}

同样,产生错误的另一行应更改为:

let strokingPath = CGPathCreateCopyByStrokingPath(layer.path, nil, 4, .Round, .Miter, 4)
于 2015-07-09T06:24:41.490 回答