2017-04-27 62 views
0

我正在使用AVfoundation(如QTPlayer)編寫OSX(Mac)應用程序來錄製iPhone屏幕。如何在iPhone屏幕方向發生變化時獲取通知

但是,當我的手機屏幕方向改變時,我不知道如何獲得通知。我試圖尋求代表,通知的解決方案,但沒有得到。而且,我不能得到iphone屏幕的大小。

我使用了AVCaptureInput AVCaptureSession AVCaptureDevice等。

我該怎麼辦?

回答

0

它已經解決了。 您需要添加一個名爲AVCaptureInputPortFormatDescriptionDidChangeNotification通知,像這樣:

NSNotificationCenter *notiCenter = [NSNotificationCenter defaultCenter]; 
id inputPortFormatDescriptionOberserver = [notiCenter addObserverForName:AVCaptureInputPortFormatDescriptionDidChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) { 
     didGetVideoDimensions = YES; 
     [wself.screenRecorderDelegate captureInputPortDidChanged]; 
     NSLog(@"AVCaptureInputPortFormatDescriptionDidChangeNotification"); 
    }]; 

,你可以得到屏幕大小像這樣:

- (CGSize)optedDeviceSize{ 
CGSize size = CGSizeZero; 
AVCaptureInputPort *port = self.videoDeviceInput.ports.firstObject; 
if (port) { 
    CMVideoDimensions videoDimensions = CMVideoFormatDescriptionGetDimensions(port.formatDescription); 
    size = CGSizeMake(videoDimensions.width, videoDimensions.height); 
} 
return size; 

}

相關問題