It ti recommended to use RTCMTLVieoView to display a video in full screen because RTCEAGLVideoView may distort picture aspect ratio when picture size is changing
id<MTLDevice> remoteDevice; #ifdef __aarch64__ remoteDevice = MTLCreateSystemDefaultDevice(); if (remoteDevice) { RTCMTLVideoView *remoteView = [[RTCMTLVideoView alloc] init]; remoteView.delegate = self; remoteView.videoContentMode = UIViewContentModeScaleAspectFit; _remoteDisplay = remoteView; _remoteDisplay.backgroundColor = [UIColor blackColor]; UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(fullscreenButton:)]; singleFingerTap.numberOfTapsRequired = 2; [_remoteDisplay addGestureRecognizer:singleFingerTap]; } #endif if (!_remoteDisplay) { RTCEAGLVideoView *remoteView = [[RTCEAGLVideoView alloc] init]; remoteView.delegate = self; _remoteDisplay = remoteView; } _remoteDisplay.translatesAutoresizingMaskIntoConstraints = NO;
To switch to full screen view, set screen dimensions to the view where stream is playing
[_remoteDisplay.widthAnchor constraintEqualToConstant: [[UIScreen mainScreen] bounds].size.width].active = YES; [_remoteDisplay.heightAnchor constraintEqualToConstant:[[UIScreen mainScreen] bounds].size.height].active = YES; [_remoteDisplay removeFromSuperview]; [_scrollView addSubview:_remoteDisplay];
To exit full screen view, set the container dimensions to the view where stream is playing
[_remoteDisplay removeFromSuperview]; [_videoContainer addSubview:_remoteDisplay]; NSLayoutConstraint *constraint =[NSLayoutConstraint constraintWithItem:_remoteDisplay attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:_remoteDisplay attribute:NSLayoutAttributeHeight multiplier:640.0/480.0 constant:0]; [_remoteDisplay addConstraint:constraint]; constraint =[NSLayoutConstraint constraintWithItem:_remoteDisplay attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationLessThanOrEqual toItem:_videoContainer attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0]; [_videoContainer addConstraint:constraint]; [_videoContainer addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[remoteDisplay]|" options:NSLayoutFormatAlignAllTop metrics:@{} views:@{@"remoteDisplay": _remoteDisplay}]]; [_videoContainer addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[remoteDisplay]|" options:0 metrics:@{} views:@{@"remoteDisplay": _remoteDisplay}]];