[英]Swift Cannot assign a value of type 'CGPath' to a value of type 'CGPath?'
我試圖只將UITextField
左上角和左下角四舍五入。 這是我正在使用的代碼:
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
let maskLayer = CAShapeLayer()
maskLayer.path = UIBezierPath(roundedRect: locationText.bounds, byRoundingCorners: .TopLeft | .BottomLeft, cornerRadii: CGSize(width: 10.0, height: 10.0)).CGPath
locationText.layer.mask = maskLayer;
}
線
maskLayer.path = UIBezierPath(roundedRect: locationText.bounds, byRoundingCorners: .TopLeft | .BottomLeft, cornerRadii: CGSize(width: 10.0, height: 10.0)).CGPath
正在產生錯誤
Cannot assign a value of type 'CGPath' to a value of type 'CGPath?'
這使我感到困惑,因為我已經能夠將值設置為可選值,而在代碼的其他地方也沒問題。 有人可以幫助我了解我在做什么錯嗎?
如果您將Swift 2.0與Xcode Beta一起使用,則可能是編譯器的一個錯誤,試圖告訴您應該使用數組來指示拐角
maskLayer.path = UIBezierPath(roundedRect: self.view.bounds, byRoundingCorners: [.TopLeft, .BottomLeft], cornerRadii: CGSize(width: 10.0, height: 10.0)).CGPath
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.