unash / BarrageRenderer

一个 iOS 上的弹幕渲染库.
https://github.com/unash/BarrageRenderer
MIT License
2.2k stars 452 forks source link

swift 3.0中点击弹幕报错 #56

Open menicor opened 7 years ago

menicor commented 7 years ago

func walkTextSpriteDescriptorWithDirection(direction:UInt) -> BarrageDescriptor{ let descriptor:BarrageDescriptor = BarrageDescriptor() descriptor.spriteName = NSStringFromClass(BarrageWalkTextSprite.self) descriptor.params["text"] = "过场文字弹幕" descriptor.params["textColor"] = UIColor(red: CGFloat(arc4random()%255) / 255, green: CGFloat(arc4random()%255) / 255, blue: CGFloat(arc4random()%255) / 255, alpha: 1) descriptor.params["speed"] = NSNumber.init(value: arc4random()%100 + 50) descriptor.params["direction"] = NSNumber.init(value: direction) descriptor.params["side"] = NSNumber.init(value: BarrageWalkSide.default.rawValue) descriptor.params["clickAction"] = { // let alertView = UIAlertView.init(title: "提示", message: "弹幕被点击", delegate: nil, cancelButtonTitle: "取消") // alertView.show() Log.shared.printLog("弹幕被点击") } return descriptor }

这样为弹幕添加了一个点击事件,但是点击之后报错 报错信息

warning: could not execute support code to read Objective-C class data in the process. This may reduce the quality of type information available.

LiMaoAtCD commented 7 years ago

@menicor NSDictionary 不支持 value 为swift的闭包函数

cornerAnt commented 7 years ago

@menicor 在BarrageDescriptor类下修改代码 在.h增加方法

在.m实现方法

} swift中使用低的方法

    descriptor.clickAction { (params) in
       // Your Code
    }

如果不想修改源码,继承或者为BarrageDescriptor扩展这个方法也可以