不' |'候选人产生预期的上下文结果类型' CGGradientDrawingOptions'

时间:2016-08-08 04:16:44

标签: ios swift xcode swift2

回到旧项目我将添加一些功能并遇到此错误。有谁知道如何消除这个?它发生在下面的代码中:

UInt32(CGGradientDrawingOptions.DrawsBeforeStartLocation) | UInt32(CGGradientDrawingOptions.DrawsAfterEndLocation))

以下是完整档案:

import UIKit

class BackgroundView: UIView {

    override func drawRect(rect: CGRect) {

        // Background View

        //// Color Declarations
        var lightPurple: UIColor = UIColor(red: 0.377, green: 0.075, blue: 0.778, alpha: 1.000)
        var darkPurple: UIColor = UIColor(red: 0.060, green: 0.036, blue: 0.202, alpha: 1.000)

        let context = UIGraphicsGetCurrentContext()

        //// Gradient Declarations
        let purpleGradient = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), [lightPurple.CGColor, darkPurple.CGColor], [0, 1])

        //// Background Drawing
        let backgroundPath = UIBezierPath(rect: CGRectMake(0, 0, self.frame.width, self.frame.height))
        CGContextSaveGState(context)
        backgroundPath.addClip()
        CGContextDrawLinearGradient(context, purpleGradient,
            CGPointMake(160, 0),
            CGPointMake(160, 568),
            UInt32(CGGradientDrawingOptions.DrawsBeforeStartLocation) | UInt32(CGGradientDrawingOptions.DrawsAfterEndLocation))
        CGContextRestoreGState(context)

    }
}

2 个答案:

答案 0 :(得分:3)

自Swift 2.0 implements OptionSetType以来

CGGradientDrawingOptions。这意味着不再需要|运算符,您可以这样写:

let options: CGGradientDrawingOptions = [.DrawsBeforeStartLocation, .DrawsAfterEndLocation]

要获得更多信息,您可以go here

答案 1 :(得分:-1)

尝试将其分组到function resetSelection() { $(".btn--reset").on("click", function(){ $(".picked").removeClass("is-active"); $(".picked").addClass("is-inactive"); $(".icon-checkmark").removeClass("is-completed"); $(".btn--submit").hide(); $(".btn--submit").removeClass("slideLeft"); starredGoaltenders = 0; starredDefencemen = 0; starredForwards = 0; console.log(starredGoaltenders, starredDefencemen, starredForwards); }); } resetSelection(); $(".btn--submit").on("click", function(){ console.log("Clicked"); resetSelection(); }); 中。