Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Для отображения потока во весь экран рекомендуется использовать RTCMTLVideoView, поскольку RTCEAGLVideoView искажает пропорции при изменении размеров

code

Code Block
languagecpp
themeRDark
    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;

Для переключения в полный экран задаем элементу, в котором проигрывается поток, размеры экрана в качестве максимальных

code

Code Block
languagecpp
themeRDark
        [_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];

Для выхода из полноэкранного режима задаем элементу, в котором проигрывается поток, размеры контейнера на экране

code

Code Block
languagecpp
themeRDark
        [_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}]];