代码之家  ›  专栏  ›  技术社区  ›  Oscar Navarro

carouselview.formsplugin未在iOS上显示

  •  1
  • Oscar Navarro  · 技术社区  · 8 年前

    我有一个Xamarin表单项目,在那里我使用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上,carousel没有显示出来。 enter image description here

    1 回复  |  直到 8 年前
        1
  •  1
  •   Tom    7 年前

    我发现把旋转木马放在相对位置对我不起作用。所做的工作是把它放在一个绝对布局/网格/堆栈布局(我没有尝试过flexlayout)。我认为这与视图大小有关,但我不确定。

    给定问题中的屏幕截图,看起来您可以简化布局以使用stacklayout。这样做会让旋转木马出现。

    推荐文章