它已經解決了。 您需要添加一個名爲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;
}