2017-04-27 32 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; 

}

相关问题