OGeek|极客世界-中国程序员成长平台

标题: ios - Swift 4 GLKViewController 更新方法未被调用 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:58
标题: ios - Swift 4 GLKViewController 更新方法未被调用

我是一名新的 swift 开发人员。我正在使用 glkit 编写代码。我在 GLKViewController 没有调用更新方法时遇到问题。请帮我修复它。谢谢你

import GLKit

游戏 Controller 类:GLKViewController{

override func viewDidLoad() {
    super.viewDidLoad()
    let glkView: GLKView = view as! GLKView
    glkView.context = EAGLContext(api: .openGLES2)!
    EAGLContext.setCurrent(glkView.context)
}

func update(){

}

override func glkView(_ view: GLKView, drawIn rect: CGRect) {

    glClearColor(1, 1, 1, 1)
    glClear(GLbitfield(GL_COLOR_BUFFER_BIT))
}

}



Best Answer-推荐答案


使用委托(delegate)!

  1. 在您的 ViewController 中,继承 GLKViewControllerGLKViewControllerDelegate
  2. viewDidLoad() 中将 self.delegate 分配给 self
  3. 写出你的 glkViewControllerUpdate(_ controller: GLKViewController)
class ViewController: GLKViewController, GLKViewControllerDelegate {
    override func viewDidLoad() {
        super.viewDidLoad()
        self.delegate = self
        ....
    }

    func glkViewControllerUpdate(_ controller: GLKViewController) {
        ....
        ....
    }
}

关于ios - Swift 4 GLKViewController 更新方法未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49633199/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4