Mac Dock像放大的iPad一样

我想通过iCarousel库为我的iPad应用程序带来像放大效果的docker。 有了这个,我可以使用下面的一段代码放大转盘的中间项目,但试图缩放中间项目的相邻项目,缩放级别比中间项目稍微小一些。

- (CATransform3D)carousel:(iCarousel *)_carousel itemTransformForOffset: :(CGFloat)offset baseTransform:(CATransform3D)transform { CGFloat MAX_SCALE = 1.95f; //max scale of center item CGFloat MAX_SHIFT = 40.0f; //amount to shift items to keep spacing the same CGFloat shift = fminf(1.0f, fmaxf(-1.0f, offset)); CGFloat scale = 1.0f + (1.0f - fabs(shift)) * (MAX_SCALE - 1.0f); transform = CATransform3DTranslate(transform, offset * _carousel.itemWidth * 1.08f + shift * MAX_SHIFT, 0.0f, 0.0f); return CATransform3DScale(transform, scale, scale, scale); } 

期待着任何帮助。 谢谢。

这个function可能是你的答案:

在这里输入图像说明

其图(scaleMax = 3,xFactor = 1):

在这里输入图像说明

该函数直接用于计算传送带偏移量的比例因子。 另外你需要把元素左右移动,这样就不会重叠(就像你已经做的那样)。 这可以通过使用函数的积分来移动项目来完成,这是可行的,但是中心的差距是巨大的。 或者可以通过计算所有缩放项目的总和来进行手动计算。 差距可以保持不变,也可以分开调整。

请注意,中心的比例等于1,边缘下降到1 / scale_max。 这是因为缩小不会产生不良的像素效应。 让你的项目视图,你想它出现在中心和边缘的意见将缩小。

这可能是这样的用法:

 -(CGFloat) scaleForX:(CGFloat)x xFactor:(CGFloat)xFactor centerScale:(CGFloat)centerScale { return (1+1/(sqrtf(x*x*x*x*xFactor*xFactor*xFactor*xFactor+1))*(centerScale-1.0))/centerScale; } - (CATransform3D)carousel:(iCarousel *)carousel itemTransformForOffset:(CGFloat)offset baseTransform:(CATransform3D)transform { //items in the center are scaled by this factor const CGFloat centerScale = 4.0f; //the larger the xFactor, the smaller the magnified area const CGFloat xFactor = 1.5f; //should the gap also be scaled? or keep it constant. const BOOL scaleGap = NO; const CGFloat spacing = [self carousel:carousel valueForOption:iCarouselOptionSpacing withDefault:1.025]; const CGFloat gap = scaleGap?0.0:spacing-1.0; //counting x offset to keep a constant gap CGFloat scaleOffset = 0.0; float x = fabs(offset); for(;x >= 0.0; x-=1.0) { scaleOffset+=[self scaleForX:x xFactor:xFactor centerScale:centerScale]; scaleOffset+= ((x>=1.0)?gap:x*gap); } scaleOffset -= [self scaleForX:offset xFactor:xFactor centerScale:centerScale]/2.0; scaleOffset += (x+0.5)*[self scaleForX:(x+(x>-0.5?0.0:1.0)) xFactor:xFactor centerScale:centerScale]; scaleOffset *= offset<0.0?-1.0:1.0; scaleOffset *= scaleGap?spacing:1.0; CGFloat scale = [self scaleForX:offset xFactor:xFactor centerScale:centerScale]; transform = CATransform3DTranslate(transform, scaleOffset*carousel.itemWidth, 0.0, 0.0); transform = CATransform3DScale(transform, scale, scale, 1.0); return transform; } 

结果: 在这里输入图像说明

你可以尝试改变不同行为的常量。 另外将指数改变为另一个偶数可以进一步扩大峰值并将下降锐化到最小比例。

您需要观看WWDC 2012的第219集 – 高级集合视图和构build自定义布局 。 我知道它涉及到收集意见,但我相信你会find一种方法来适应该代码:)