У меня есть довольно длительный метод для приложения остановки движения, которое немного отличается для каждого из различных вариантов прессованных, таймеров, уверенные таймеров и т.д.Как определить постоянный метод
Можно определить основное тело методы :
// 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);
}];
и просто сделать вариации способа с таймерами и т.д.
Сначала я попытался сделать одиночки, но, хотя я получил метод, называемый у меня были другие проблемы с сохранением и записи в файл. Могу ли я сделать MACRO из метода?
Я исследовал на SO здесь iOS create macro
я на правильном пути? могу ли я определить метод, а не изображение, как в этом примере.
Возможно, вы захотите создать класс утилиты, содержащий этот метод, вы можете создать экземпляр класса, чтобы выполнить фактическую обработку. Если вы не хотите создавать экземпляр класса, вы можете создать класс с помощью методов класса (например, '+ (void) doSomeThing') и использовать их напрямую. – jessecurry