swift3 - Swift 3 绘图应用程序中的错误

标签 swift3 drawing xcode8

我正在使用 Xcode 8 在 Swift 3 中制作绘图应用程序。我尝试按照教程进行操作,但似乎无法在该网站的评论部分找到这些错误的答案。

以下是我不断收到的两组错误:

This is the first set of errors that I get

this is the second set of errors that I am getting

context?.setLineCap(kCALineCapRound)
context?.setLineWidth(brushWidth)
context?.setStrokeColor(red: red, green: green, blue: blue, alpha: 1.0)
context?.setBlendMode(kCGBlendModeNormal)

UIGraphicsBeginImageContext(mainImageView.frame.size)
    mainImageView.image?.drawInRect(CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height), blendMode: kCGBlendModeNormal, alpha: 1.0)
tempImageView.image?.drawInRect(CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height), blendMode: kCGBlendModeNormal, alpha: opacity)
mainImageView.image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

如果有人可以帮助我找出如何解决这两个错误,我将不胜感激。

最佳答案

如果您发现代码有问题,请检查official API Reference .

setLineCap(_:)

Declaration

func setLineCap(_ cap: CGLineCap)

CGLineCap

Enumeration

CGLineCap

您需要将 CGLineCap 值传递给 setLineCap(_:) 方法,在 Swift 3 中它是枚举,因此您需要传递一个枚举情况。

这一行:

context?.setLineCap(kCALineCapRound)

应该是这样的:

context?.setLineCap(CGLineCap.round)

或者只是像这样:

context?.setLineCap(.round)

(顺便说一下,即使在以前的 Swift 和 Objective-C 中,kCALineCapRound 也不是 setLineCap 的有效常量——CGContextSetLineCap。它应该是kCGLineCapRound)


再次...

setBlendMode(_:)

Declaration

func setBlendMode(_ mode: CGBlendMode)

CGBlendMode

Enumeration

CGBlendMode

更改此行:

context?.setBlendMode(kCGBlendModeNormal)

对此:

context?.setBlendMode(CGBlendMode.normal)

或者这个:

context?.setBlendMode(.normal)

您的第二组错误需要类似的更改(以及一些简单的修复)。


你最好花一些时间找到一个好的 Swift 3 教程,否则你可能会花更多的时间来学习如何将代码从 Swift 2 迁移到 Swift 3,而不是在 Swift 3 中制作应用程序。

关于swift3 - Swift 3 绘图应用程序中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41080863/

相关文章:

ios - 如何根据 View Controller 中的输入在 View 中绘制形状?

ios - Xcode 8 Storyboard View Controller 全蓝色背景

ios - 将使用 Cocoapods 1.0.1 的 iOS 应用程序从 Swift 2.2 迁移到 3.0

按日期快速排序核心数据(不仅仅是时间)

drawing - Photoshop 撤销系统

javascript - 试图将 SVG 绘制到 Canvas 上,但它被缩短了

swift - watchOS 3 getSupportedTimeTravelDirections

cocoa - 如何测试 NSTouchBar

ios - setNavigationBarHidden 无法以编程方式工作?

json - Alamofire 4、Swift 3 和构建 json 主体