Swift 2.0和CVDisplayLinkSetOutputCallback通过@convention(c)实现
有没有人能够在不桥接Objective-C代码的情况下使用CVDisplayLink定时器 通过添加@convention(c),这应该是可能的,但在尝试使用CVDisplayLinkSetOutputCallback时仍然会出现分段错误:11Swift 2.0和CVDisplayLinkSetOutputCallback通过@convention(c)实现,swift,cocoa,core-graphics,core-animation,core-video,Swift,Cocoa,Core Graphics,Core Animation,Core Video,有没有人能够在不桥接Objective-C代码的情况下使用CVDisplayLink定时器 通过添加@convention(c),这应该是可能的,但在尝试使用CVDisplayLinkSetOutputCallback时仍然会出现分段错误:11 required init?(coder: NSCoder) { super.init(coder: coder) CVDisplayLinkCreateWithActiveCGDisplays(&displayLin
required init?(coder: NSCoder) {
super.init(coder: coder)
CVDisplayLinkCreateWithActiveCGDisplays(&displayLink)
CVDisplayLinkSetOutputCallback(displayLink!, callback, UnsafeMutablePointer<Void>(unsafeAddressOf(self!)) )
}
//call back declarations
let callback : @convention(c)(displayLink: CVDisplayLink, inNow: UnsafePointer<CVTimeStamp>, inOutputTime: UnsafePointer<CVTimeStamp>, flagsIn: CVOptionFlags, flagsOut: UnsafeMutablePointer<CVOptionFlags>, displayLinkContext: UnsafeMutablePointer<Void>) -> CVReturn =
{ (displayLink, inNow, inOutputTime, flagsIn, flagsOut, displayLinkContext) -> CVReturn in
let context = UnsafeMutablePointer<GraphView>(displayLinkContext)
let newContext = context.memory
let error = newContext.getFrameForTime(inOutputTime)
return error;
return kCVReturnSuccess
}
required init?(编码器:NSCoder){
super.init(编码器:编码器)
CVDisplayLinkCreateWithActiveCGDisplays(&displayLink)
CVDisplayLinkSetOutputCallback(displayLink!、callback、UnsafeMutablePointer(unsafeAddressOf(self!))
}
//回调声明
let回调:@convention(c)(displayLink:CVDisplayLink,inNow:UnsafePointer,inOutputTime:UnsafePointer,flagsIn:CVOptionFlags,flagsOut:UnsafeMutablePointer,displayLinkContext:UnsafeMutablePointer)->CVReturn=
{(displayLink、inNow、inOutputTime、flagsIn、flagsOut、displayLinkContext)->CVReturn in
let context=unsafemeutablepointer(displayLinkContext)
让newContext=context.memory
let error=newContext.getFrameForTime(inOutputTime)
返回误差;
返回kCVReturnSuccess
}
我现在可以这样做吗?还是桥接仍然是实现精确计时器的必要条件?我用swift编写了这段代码。我不确定它是否有c桥。我在swift里得到了这个密码。我不确定它是否有c桥。