Open menicor opened 7 years ago
@menicor NSDictionary 不支持 value 为swift的闭包函数
@menicor 在BarrageDescriptor类下修改代码 在.h增加方法
在.m实现方法
(void)clickAction:(BarrageClickAction)clickAction{
self.params[@"clickAction"] = clickAction;
} swift中使用低的方法
descriptor.clickAction { (params) in
// Your Code
}
如果不想修改源码,继承或者为BarrageDescriptor扩展这个方法也可以
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.