CarouselView.FormsPlugin未在iOS上显示

时间:2018-07-11 15:49:23

标签: 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

1 个答案:

答案 0 :(得分:1)

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

给出问题中的屏幕截图,看来您可以简化布局以使用StackLayout。这样做应该可以显示CarouselView。