相关疑难解决方法(0)

如何在swift中将COpaquePointer转换为某种类型(特别是CGContext?)

我在swift中有以下代码,不能编译:

class CustomView: NSView {
  override func drawRect(dirtyRect: NSRect) {
    var contextPointer: COpaquePointer = NSGraphicsContext.currentContext()!.graphicsPort()
    var context: CGContext? = contextPointer as? CGContext
    CGContextSetRGBFillColor(context, 1, 0, 0, 1)
    CGContextFillRect(context, CGRectMake(0, 0, 100, 100))
    CGContextFlush(context)
  }
}
Run Code Online (Sandbox Code Playgroud)

如何将COpaquePointer转换为CGContext?

swift

8
推荐指数
3
解决办法
3591
查看次数

标签 统计

swift ×1