可能目前这实际上是不可能的,这是不幸的.我正在尝试调用CoreMIDI API来设置MIDI输入.这就是我在Swift中要做的事情:
var midiClient = MIDIClientRef()
var inputPort = MIDIEndpointRef()
var status: OSStatus
func readProc(packetList: UnsafePointer<MIDIPacketList>, readProcRefCon: UnsafeMutablePointer<Void>, srcConnRefCon: UnsafeMutablePointer<Void>) -> Void {
}
status = MIDIClientCreate("MIDI client", nil, nil, &midiClient);
status = MIDIDestinationCreate(midiClient, "MIDI input", readProc, nil, &inputPort);
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:'(UnsafePointer,UnsafeMutablePointer,UnsafeMutablePointer) - > Void'不能转换为'MIDIReadProc'
MIDIReadProc的typedef如下:
typealias MIDIReadProc = CFunctionPointer<((UnsafePointer<MIDIPacketList>, UnsafeMutablePointer<Void>, UnsafeMutablePointer<Void>) -> Void)>
Run Code Online (Sandbox Code Playgroud)
有没有办法让我的readProc方法的函数指针传递给MIDIDestinationCreate API?
我创建了一个UIBezierPath,但我不知道如何访问它的起点.我试过这样做:
let startPoint = path.currentPoint
Run Code Online (Sandbox Code Playgroud)
该属性currentPoint给了我最后一点,而不是起点.我需要起点的原因是因为我想在路径的起点放置一个图像.
有任何想法吗?
我在CALayers中绘制了大约20个简单的形状,如下面的那个(在CAShapelayer中绘制的CGPath).现在我有一个非常长的文件,包含这种格式的所有20个形状.当创建父UIView时,它会根据前一个屏幕中选择的内容加载其中一个形状.这样做很好,但保持形状代码太麻烦了.将下面的代码块存储到单个文件中的最佳方法是什么?我可以在需要时调用并执行它(例如:star.txt,apple.txt,moon.txt,tree.txt):
CALayer* root = [[CALayer alloc] init];
root.name = nil;
root.bounds = CGRectMake(0.000000, 0.000000, 768.000000, 768.000000);
root.frame = CGRectMake(0.000000, 0.000000, 768.000000, 768.000000);
[root addSublayer:root];
[root release];
CALayer* root_layer1 = [[CALayer alloc] init];
root_layer1.name = nil;
root_layer1.bounds = CGRectMake(0.000000, 0.000000, 768.000000, 768.000000);
root_layer1.frame = CGRectMake(0.000000, 0.000000, 768.000000, 768.000000);
[someUIView.layer addSublayer:root_layer1];
[root_layer1 release];
CAShapeLayer* root_layer1_layer2 = [[CAShapeLayer alloc] init];
CGMutablePathRef root_layer1_layer2_path_pathref = CGPathCreateMutable();
CGPathMoveToPoint(root_layer1_layer2_path_pathref, NULL, 415.493011, 49.774002);
CGPathAddLineToPoint(root_layer1_layer2_path_pathref, NULL, 448.989014, 153.523010);
CGPathAddCurveToPoint(root_layer1_layer2_path_pathref, NULL, 458.575012, 183.251007, 485.170044, 202.583008, 516.384033, 202.510010);
CGPathAddLineToPoint(root_layer1_layer2_path_pathref, NULL, 625.388062, …Run Code Online (Sandbox Code Playgroud)