2013-08-21 48 views
0

我有一個停止運動應用程序,爲每個壓的各種選項,定時器,自動定時器略有不同的是一個相當長法等如何定義一個常數法

可以定義方法的主體:用定時器等

開始我嘗試做一個單身,但我雖然有所謂的方法,我與保存等問題和寫入文件的方法的

// 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

我在正確的軌道上?我可以定義一個方法,而不是像那個例子那樣的圖像:

+0

您可能想要創建一個包含此方法的實用程序類,您可以創建該類的實例以執行實際處理。如果你不想實例化一個類,你可以用類方法創建一個類(例如'+(void)doSomeThing')並直接使用它們。 – jessecurry

回答

2

儘管可能,使宏從方法中出來,但由於各種原因,這是一個糟糕的想法。

爲什麼不把它作爲一個類的方法?您不必擔心類實例的管理,也不會混淆全局名稱空間。

+0

好的一點是重視宏觀。所以如果我在.h中聲明我的方法爲+(void)myMethod;我如何/在哪裏把這in.m檢索我檢查了這個http://stackoverflow.com/questions/1053592/what-is-the-difference-between-class-and-instance-methods – JSA986

+0

在實現塊,就像實例方法一樣。 – Jeff

+0

然後我不明白類方法的概念。你有沒有例子? – JSA986