ios 'CGPointMake' 在 swift 中不可用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39336793/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 10:03:50  来源:igfitidea点击:

'CGPointMake' is unavailable in swift

iosswiftswift3

提问by RileyDev

I have a Gradient class which I am trying to convert to Swift 3 but I get the following error

我有一个 Gradient 类,我试图将其转换为 Swift 3,但出现以下错误

'CGPointMake' is unavailable in swift

'CGPointMake' 在 swift 中不可用

for

为了

func configureGradientView() {

    let color1 = topColor ?? self.tintColor as UIColor
    let color2 = bottomColor ?? UIColor.black as UIColor
    let colors: Array <AnyObject> = [ color1.cgColor, color2.cgColor ]
    let layer = self.layer as! CAGradientLayer

    layer.colors = colors
    layer.startPoint = CGPointMake(startX, startY)
    layer.endPoint = CGPointMake(endX, endY)
}

Can anyone help me out with what I can use instead of CGPointMake

任何人都可以帮助我解决我可以使用的东西而不是 CGPointMake

Here's the full class;

这是完整的课程;

@IBDesignable public class XGradientView: UIView {

@IBInspectable public var topColor: UIColor? {
    didSet {
        configureGradientView()
    }
}
@IBInspectable public var bottomColor: UIColor? {
    didSet {
        configureGradientView()
    }
}
@IBInspectable var startX: CGFloat = 0.0 {
    didSet{
        configureGradientView()
    }
}
@IBInspectable var startY: CGFloat = 1.0 {
    didSet{
        configureGradientView()
    }
}
@IBInspectable var endX: CGFloat = 0.0 {
    didSet{
        configureGradientView()
    }
}
@IBInspectable var endY: CGFloat = 0.0 {
    didSet{
        configureGradientView()
    }
}

public class func layeredClass() -> AnyClass {
    return CAGradientLayer.self
}

public required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)!
    configureGradientView()
}

override init(frame: CGRect) {
    super.init(frame: frame)
    configureGradientView()
}

public override func tintColorDidChange() {
    super.tintColorDidChange()
    configureGradientView()
}

func configureGradientView() {

    let color1 = topColor ?? self.tintColor as UIColor
    let color2 = bottomColor ?? UIColor.black as UIColor
    let colors: Array <AnyObject> = [ color1.cgColor, color2.cgColor ]
    let layer = self.layer as! CAGradientLayer

    layer.colors = colors
    layer.startPoint = CGPointMake(startX, startY)
    layer.endPoint = CGPointMake(endX, endY)
}
}

回答by Adnan Aftab

In swift you can create a CGPointin swifty way CGPoint(x: xPos, y:yPos). So change your CGPointMake(startX, startY)to CGPoint(x: startX, y: startY)

在 swift 中,您可以CGPoint以 swifty 的方式创建一个CGPoint(x: xPos, y:yPos)。所以改变你CGPointMake(startX, startY)CGPoint(x: startX, y: startY)

回答by pkc456

swift 3 emphasizes in use of named Parameters.

swift 3 强调使用命名参数。

CGPointCan be created like this.

CGPoint可以这样创建。

let point = CGPoint(x: 0,y :0) // CGFloat, Double, Int