我有一個停止運動應用程序,爲每個壓的各種選項,定時器,自動定時器略有不同的是一個相當長法等如何定義一個常數法
可以定義方法的主體:用定時器等
開始我嘗試做一個單身,但我雖然有所謂的方法,我與保存等問題和寫入文件的方法的
// 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嗎?
我研究了所以這裏iOS create macro
我在正確的軌道上?我可以定義一個方法,而不是像那個例子那樣的圖像:
您可能想要創建一個包含此方法的實用程序類,您可以創建該類的實例以執行實際處理。如果你不想實例化一個類,你可以用類方法創建一個類(例如'+(void)doSomeThing')並直接使用它們。 – jessecurry