我有一个相当冗长的停止动作应用程序方法,对于按下的各种选项,计时器,自定时器等,每个都略有不同
可以定义方法的主体:
// initiate a still image capture, return immediately
// the completionHandler is called when a sample buffer has been captured
AVCaptureConnection *stillImageConnection = [stillImageOutput connectionWithMediaType:AVMediaTypeVideo];
[stillImageOutput captureStillImageAsynchronouslyFromConnection:stillImageConnection
completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *__strong error) {
// set up the AVAssetWriter using the format description from the first sample buffer captured
if ( !assetWriter ) {
outputURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%llu.mov", NSTemporaryDirectory(), mach_absolute_time()]];
//NSLog(@"Writing movie to \"%@\"", outputURL);
CMFormatDescriptionRef formatDescription = CMSampleBufferGetFormatDescription(imageDataSampleBuffer);
if ( NO == [self setupAssetWriterForURL:outputURL formatDescription:formatDescription] )
return;
}
// re-time the sample buffer - in this sample frameDuration is set to 5 fps
CMSampleTimingInfo timingInfo = kCMTimingInfoInvalid;
timingInfo.duration = frameDuration;
timingInfo.presentationTimeStamp = nextPTS;
CMSampleBufferRef sbufWithNewTiming = NULL;
OSStatus err = CMSampleBufferCreateCopyWithNewTiming(kCFAllocatorDefault,
imageDataSampleBuffer,
1, // numSampleTimingEntries
&timingInfo,
&sbufWithNewTiming);
if (err)
return;
// append the sample buffer if we can and increment presnetation time
if ( [assetWriterInput isReadyForMoreMediaData] ) {
if ([assetWriterInput appendSampleBuffer:sbufWithNewTiming]) {
nextPTS = CMTimeAdd(frameDuration, nextPTS);
}
else {
NSError *error = [assetWriter error];
NSLog(@"failed to append sbuf: %@", error);
}
}
// release the copy of the sample buffer we made
CFRelease(sbufWithNewTiming);
}];
只是使用计时器等方法来改变方法
首先我尝试制作一个单例,但是虽然我得到了一个名为my的方法,但在保存和写入文件方面存在其他问题。我可以用方法制作MACRO吗?
我在这里研究了iOS create macro
我是否在正确的轨道上?我可以定义一个方法而不是像那个例子中的图像
答案 0 :(得分:2)
出于各种原因,尽可能从方法中制作宏是一个糟糕的主意。
为什么不把它变成一个类方法呢?您不必担心类实例的管理,也不会混淆全局命名空间。