启用环绕的线性旋转木马
Linear Carousel with wrap enabled
我想制作一个启用了环绕的线性旋转木马(这样你就可以在任一方向无限滚动,它只会环绕)他们有一个 CarouselType.Linear,但它没有启用环绕。任何人都知道如何使用 iCarousel 或 UICollectionViews 做到这一点?我找不到关于如何制作自定义 iCarousel 布局的任何好的资源...那里有什么好的参考资料吗?
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;
}
}
}
想通了。覆盖 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;
}
/*--------------------------------------------------------------------------------*/
}
/*--------------------------------------------------------------------------------*/
我想制作一个启用了环绕的线性旋转木马(这样你就可以在任一方向无限滚动,它只会环绕)他们有一个 CarouselType.Linear,但它没有启用环绕。任何人都知道如何使用 iCarousel 或 UICollectionViews 做到这一点?我找不到关于如何制作自定义 iCarousel 布局的任何好的资源...那里有什么好的参考资料吗?
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;
}
}
}
想通了。覆盖 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;
}
/*--------------------------------------------------------------------------------*/
}
/*--------------------------------------------------------------------------------*/