ios - CarouselView.FormsPlugin 未在 iOS 上显示

标签 ios xamarin.forms carousel

我有一个 Xamarin Forms 项目,我在其中使用 CarouselView 的 NuGet,它在 Android 上运行完美,但在 iOS 上不显示。

我试过Carousel 5.0.0和5.2.0的版本

这是 AppDelegate 类

using CarouselView.FormsPlugin.iOS;

namespace FortiaApp.iOS
{
    // The UIApplicationDelegate for the application. This class is responsible for launching the 
    // User Interface of the application, as well as listening (and optionally responding) to 
    // application events from iOS.
    [Register("AppDelegate")]
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
    {
        {
            global::Xamarin.Forms.Forms.Init();
            RoundedBoxViewRenderer.Init();
            AnimationViewRenderer.Init();
            CarouselViewRenderer.Init();
            LoadApplication(new App());

            return base.FinishedLaunching(app, options);
        }
    }
}

这是我的应用程序的代码

private View[] _views;
public frmDetalle(int idUsuario)
        {
            InitializeComponent();
            this.idUsuario = idUsuario;
            lblSaludo.Text = utileriasServices.getSaludo();
            lblFecha.Text = utileriasServices.getFecha();

            Device.BeginInvokeOnMainThread(async () =>
            {
                var response = await fortiaServices.PostAsinc<AccountModel>(new Account { IdUser = this.idUsuario }, "/GetInfoInit");
                if (response != null)
                {
                    this.accountModel = response;

                    Device.BeginInvokeOnMainThread(async () =>
                    {
                        var responseToken = await fortiaServices.PostAsinc<TokenApiResponse>(new Object(), "/GetToken");

                        if (responseToken != null)
                        {
                            this.accountModel.tokenApi = responseToken;
                            this.accountModel.idTarjeta = this.accountModel.account.idTarjetaPrincipal;

                            //Agrega tarjetas
                            _views = new View[accountModel.Tarjetas.Count + 1];
                            _views[0] = new frmTarjeta(this.accountModel, this.accountModel.idTarjeta);

                            for (var i = 0; i < accountModel.Tarjetas.Count; i++)
                            {
                                this.accountModel.idTarjeta = this.accountModel.Tarjetas[i].IdTarjeta;
                                _views[i + 1] = new frmTarjeta(this.accountModel, this.accountModel.Tarjetas[i].IdTarjeta);
                            }
                            Carousel.ItemsSource = _views;
                            await GetInfoPrincipal();
                        }
                        else
                        {
                            await DisplayAlert("Tenemos problemas", "Los servicios no estan disponibles", "Continuar");
                            await Navigation.PushAsync(new frmLogin());
                        }
                    });

                    await Navigation.PopModalAsync(false);
                }
                else
                {
                    await Navigation.PopModalAsync(false);
                    await DisplayAlert("Tenemos problemas", "Los servicios no estan disponibles", "Continuar");
                    await Navigation.PushAsync(new frmLogin());
                }
            });
        }

这是mi文件xaml

xmlns:carousel="clr-namespace:CarouselView.FormsPlugin.Abstractions;assembly=CarouselView.FormsPlugin.Abstractions"

 <carousel:CarouselViewControl
                            RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height,Factor=.16,Constant=0}"
                            RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width,Factor=1,Constant=0}"
                            RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent,Property=Height,Factor=.42,Constant=0}"
                                    x:Name="Carousel"
                                    Grid.Row="0"
                                    Grid.Column="0"
                                    Grid.ColumnSpan="2"
                                    Orientation="Horizontal"
                                    Position="0"
                                    ShowIndicators="True"
                                    ShowArrows="False"                                    
                                    CurrentPageIndicatorTintColor="#93B638"
                                    IndicatorsTintColor="White"
                                    PositionSelected="OnCarouselPositionSelected"
                                    VerticalOptions="CenterAndExpand"
                                    HorizontalOptions="CenterAndExpand"/>

这是它在两个平台上的样子,如您所见,在 Android 上它运行完美,但在 iOS 上不显示轮播 enter image description here

最佳答案

我发现将 CarouselView 放在 RelativeLayout 中对我不起作用。起作用的是将它放在 AbsoluteLayout/Grid/StackLayout 中(我没有尝试过 FlexLayout)。我认为这与 View 大小有关,但我不确定。

鉴于您问题中的屏幕截图,您似乎可以简化布局以使用 StackLayout。这样做应该允许 CarouselView 出现。

关于ios - CarouselView.FormsPlugin 未在 iOS 上显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51289650/

相关文章:

ios - DBAccess:提交不起作用

ios - watchOS 2.2 应用程序如何确定其配对的 iPhone 是否已切换到另一台 Apple Watch?

html - 如何使幻灯片标题响应并在页面最小化时消失?

jQuery slider 轮播停止在末尾

ios - [NSManagedObject setSwitchState :]: unrecognized selector sent in Objective-C

c# - Xamarin 中的蓝牙打印

c# - Xamarin.Forms(Android)蓝牙间歇性工作

c# - 如何在 Xamarin forms Android 和 iOS 中实现 Deeplink(Universal Linking)?

jquery - bootstrap 中带有 carousal 的下拉菜单的子菜单项未显示

ios - 有没有办法让 NSFetchedResultsController 检测多个实体的变化?