0

我正在使用 FlowListView 进行视频矩阵视图(1x1-2x2-3x3 视图)。对于 iOS 应用,UIView 渲染器用于与第三方视频 SDK 集成。这是 FlowListView。

    <flv:FlowListView x:Name="VideoFlowList" FlowColumnCount="{Binding ColumnCount}" RowHeight="{Binding RowHeight, Mode=TwoWay}"
                  SeparatorVisibility="None" HasUnevenRows="false" BackgroundColor="Transparent"
                  FlowColumnMinWidth="80" FlowTotalRecords="{Binding TotalRecords, Mode=TwoWay}" FlowItemsSource="{Binding Items}">

    <flv:FlowListView.FlowColumnTemplate>
        <DataTemplate>
            <Grid x:Name="VideoGrid" Padding="2" BackgroundColor="{Binding SelectedBorderColour, Mode=TwoWay}" RowSpacing="1" ColumnSpacing="1">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <video:CameraView x:Name="MyCameraView" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" BackgroundColor="Black" />
                <Image x:Name="AddIcon" Source="panel_add.png" Grid.Row="0" Grid.Column="0" IsVisible="{Binding CameraNotAssigned}"
                       HorizontalOptions="Center" VerticalOptions="Center" Aspect="AspectFit" BackgroundColor="Transparent" WidthRequest="50" HeightRequest="50">
                    <Image.GestureRecognizers>
                        <TapGestureRecognizer Command="{Binding BindingContext.AddCameraCommand, Source={x:Reference BrowseItemsPage}}" 
                                              CommandParameter="{x:Reference VideoGrid}" NumberOfTapsRequired="1" />
                    </Image.GestureRecognizers>
                </Image>

                <Label x:Name="Label" HorizontalOptions="Fill" HorizontalTextAlignment="Center" VerticalOptions="End"
                       BackgroundColor="Silver" Opacity="0.5" Text="{Binding CameraName, Mode=TwoWay}" TextColor="Black"/>
            </Grid>
        </DataTemplate>
    </flv:FlowListView.FlowColumnTemplate>
</flv:FlowListView>

在矩阵视图启动时,它显示 4 个视图(视图模型中的 ColumnCount = 2,ToTalRecords = 4)并且每次都有效。切换到任何其他视图也可以。但偶尔从单个视图切换到 4 个视图时,只有 2 个新元素,而不是覆盖的 OnElementChanged 中的 4 个。如何确保每次都能获得 4 个新元素?

请注意,从 9 个视图切换到 4 个视图时不会发生此问题。

这是 ViewRenderer 的代码。

public class VideoRender : ViewRenderer<CameraView, UIVideoView>
{
    private UIVideoView _videoView;

    protected override void OnElementChanged(ElementChangedEventArgs<CameraView> e)
    {
        base.OnElementChanged(e);
        if (e.OldElement != null)
        {
            //Unsubscribe
            _videoView.Tapped -= OnVideoViewTapped;
            Log.Debug($"OldElement CameraIndex {e.OldElement.CameraIndex}, PlayWndHandle {e.OldElement.PlayWndHandle}");
        }
        if (e.NewElement != null)
        {
            //Control is TNativeView, CameraView
            if (Control == null)
            {
                _videoView = new UIVideoView(Element);
                SetNativeControl(_videoView);
            }

            //Element.PlayWndHandle = Handle;

            if (_videoView.Subviews.Length > 0)
            {
                Element.PlayWndHandle = _videoView.Subviews[0].Handle;
            }
            App.PlayWndHandles.Add(Element.PlayWndHandle);
            Log.Debug($"NewElement CameraIndex {Element.CameraIndex}, PlayWndHandle {Element.PlayWndHandle}");
            Log.Debug($"App.PlayWndHandles[{App.PlayWndHandles.Count - 1}]: {Element.PlayWndHandle}");

            // Subscribe
            _videoView.Tapped += OnVideoViewTapped;
        }
    }

}

I added a subview in the UIView UIVideoView and play the video in the subview. Is the issue related to the way I use the subview?
        
void Initialize()
{
    //place the video in subview
    var subView = new UIView();
    subView.UserInteractionEnabled = true;
    AddSubview(subView);
    if (Subviews.Length > 0)
    {
        Subviews[0].Frame = new CoreGraphics.CGRect(0, 0, 100, 100);
    }
}
4

1 回答 1

0

似乎使用 4 个单独的播放窗口句柄列表(每个矩阵大小一个)可以克服句柄管理问题。通过清除列表中的句柄来特殊处理单个视图,因为句柄将始终被删除并重新创建。

于 2020-10-16T04:18:52.077 回答