iCarousel iOS,侧面尺寸缩小

问题描述 投票:0回答:1

我正在尝试创建一个圆形旋转木马。我想总是一次显示 3 个。一个视图是集中的,另外两个(上一个和下一个)尺寸缩小,如下图所示:

我正在使用 Xamarin.iOS,但欢迎使用 swift 和 object-c 的解决方案。

这是我能得到的最接近的:

我在 iCarouselDelegate 中有这个

public override nfloat ValueForOption(iCarousel carousel, iCarouselOption option, nfloat value)
{
        switch (option)
        {
            case iCarouselOption.OffsetMultiplier:
                return 2f;

            case iCarouselOption.Wrap:
                return 1.5f;

            case iCarouselOption.VisibleItems:
                return count;

            case iCarouselOption.Spacing:
                return 2f;

            default:
                return value;
        }
}

还有:

ViewCarousel.Type = iCarouselType.Rotary;

ios swift objective-c xamarin.ios
1个回答
0
投票

我已经设法用以下代码行解决了我的问题:

    public override CATransform3D ItemTransformForOffset(iCarousel carousel, nfloat offset, CATransform3D transform)
    {
        // How much smaller the left and right views should be relative to the center view (expressed as pixels)
        float viewSizeDifference = -100;

        // The horizontal spacing between the views (expressed as a multiple of the views width)
        float viewDistance = 1.17f;

        float transformZ = (float)(Math.Min(1.0f, Math.Abs(offset)) * viewSizeDifference);

        return transform.Translate(offset * carousel.ItemWidth * viewDistance, 0f, transformZ);
    }

但要使其工作,您还必须将类型更改为自定义:

ViewCarousel.Type = iCarouselType.Custom;
© www.soinside.com 2019 - 2024. All rights reserved.