【问题标题】:Linear Carousel with wrap enabled启用环绕的线性轮播
【发布时间】:2015-03-20 21:42:13
【问题描述】:

我想制作一个启用了换行的线性轮播(因此您可以在任一方向上无限滚动,它只会环绕)他们有一个 CarouselType.Linear,但它没有启用换行。任何人都知道如何使用 iCarousel 或 UICollectionViews 做到这一点?我找不到任何关于如何制作自定义 iCarousel 布局的好资源......那里有什么好的参考资料吗?

Alliance Carousel

        this.Carousel = new CarouselView(frame)
        {
            DataSource = new CylindericalDataSource(this),
            Delegate = new CylindericalDelegate(this)
        };
        this.Carousel.CarouselType = CarouselType.Linear;
        this.Carousel.ConfigureView();
        this.View.AddSubview(this.Carousel);

------------编辑--------------

回答@Rahul 的问题

    public override void DidScroll (CarouselView carouselView)
    {
        base.DidScroll (carouselView);

        nint numOfItems = carouselView.NumberOfItems;
        if (this._parentController != null &&
            this._parentController._studioViewController != null &&
            this._parentController._studioViewController.SuccessfullyReceivedProjectAndPageData () &&
            this._parentController._studioViewController.HasFlowCardCarouselFinishedLoading () &&
            numOfItems > 0)
        {
            // Enforce min and max values fro ScrollOffset so the user can't scroll the carousel off screen.  This is required when wrapping is turned off. 
            nfloat maxScrollOffset = ((nfloat)numOfItems) - 1f;
            nfloat minScrollOffset = 0f;
            if (carouselView.ScrollOffset < minScrollOffset)
            {
                carouselView.ScrollOffset = minScrollOffset;
            }
            if (carouselView.ScrollOffset > maxScrollOffset)
            {
                carouselView.ScrollOffset = maxScrollOffset;
            }
        }
    }

【问题讨论】:

    标签: c# ios xamarin.ios uicollectionview icarousel


    【解决方案1】:

    想通了。覆盖 ValueForOption 方法并强制 CarouseOption.Wrap 等于 1.0f。见下文

        /*--------------------------------------------------------------------------------*/
        // Class: CylindericalDelegate
        /*--------------------------------------------------------------------------------*/
    
        public class CylindericalDelegate : CarouselViewDelegate
        {
    
            /*--------------------------------------------------------------------------------*/
            // Constructors
            /*--------------------------------------------------------------------------------*/
    
            public CylindericalDelegate()
            {
            }
    
            /*--------------------------------------------------------------------------------*/
            // CylindericalDelegate Implementation
            /*--------------------------------------------------------------------------------*/
    
            public override nfloat ValueForOption(CarouselView carousel, CarouselOption option, nfloat aValue)
            {
                if (option == CarouselOption.Spacing)
                {
                    return aValue * 1.1f;
                }
                if (option == CarouselOption.Wrap)
                {
                    return 1.0f;
                }
                return aValue;
            }
    
            /*--------------------------------------------------------------------------------*/
    
        }
    
        /*--------------------------------------------------------------------------------*/
    

    【讨论】:

    • 谢谢.. 如果我想在最后一张图片/幻灯片上停止轮播怎么办?
    • 不幸的是,像这样使用它时没有内置。我附上了我的代码,该代码负责停止在最后一张图像上的行为。您必须使用 ScrollOffset 覆盖 DidScroll 并自己强制执行。 scrollOffset 基于索引而不是框架。
    猜你喜欢
    • 2015-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-12
    • 1970-01-01
    • 1970-01-01
    • 2019-08-12
    相关资源
    最近更新 更多