iCarousel詳解

Documentation

Supported OS & SDK Versions

支持的OS & SDK版本

Supported build target - iOS 5.1 / Mac OS 10.7 (Xcode4.3.3, Apple LLVM compiler 3.1)

支持的編譯目標(biāo)-iOS 5.1 / Mac OS 10.7 (Xcode 4.3.3, Apple LLVM compiler3.1)

Earliest supported deployment target - iOS 4.3 / Mac OS10.7

最早支持的開發(fā)目標(biāo)-iOS 4.3 / Mac OS 10.7

Earliest compatible deployment target - iOS 3.2 / Mac OS10.6

最早兼容的開發(fā)目標(biāo)-iOS 3.2 / Mac OS10.6

NOTE: 'Supported' means that the library has been testedwith this version. 'Compatible' means that the library should work on this OSversion (i.e. it doesn't rely on any unavailable SDK features) but is no longerbeing tested for compatibility and may require tweaking or bug fixes to runcorrectly.

注意:“支持”的意思是這個(gè)版本的庫已經(jīng)被測試過了抛腕。“可兼容”的意思是在這個(gè)版本上這個(gè)庫是可以工作的(它并不依賴于任何不可獲得的sdk特性)但是已經(jīng)不再對(duì)兼容性做測試,并且可能需要稍作改動(dòng)或bug修復(fù)來正確運(yùn)行。

ARC Compatibility

arc兼容性

As of version 1.6.1, iCarousel automatically works withboth ARC and non-ARC projects through conditional compilation. There is no needto exclude iCarousel files from the ARC validation process, or to convertiCarousel using the ARC conversion tool.

作為1.6.1版本只祠,iCarousel通過條件性編譯捺癞,可以自動(dòng)工作在arc和非arc的工程中。沒有必要從arc確認(rèn)程序中排除iCarousel文件绞绒,或者去使用arc轉(zhuǎn)換工具去轉(zhuǎn)換iCarousel拦耐。

Thread Safety

線程安全

iCarousel is derived from UIView and - as with all UIKitcomponents - it should only be accessed from the main thread. You may wish touse threads for loading or updating carousel contents or items, but alwaysensure that once your content has loaded, you switch back to the main threadbefore updating the carousel.

iCarousel源于UIView耕腾,并且-和所有UIKit組建一樣-它只能從主線程中獲取。你可能希望使用線程來下載或更新carousel內(nèi)容或條目杀糯,但是總是確保一旦你的內(nèi)容已經(jīng)被加載了扫俺,在更新carousel之前你需要切換回主線程。

Installation

安裝

To use the iCarousel class in an app, just drag theiCarousel class files (demo files and assets are not needed) into your projectand add the QuartzCore framework.

在app中使用iCarousel類固翰,只需要將iCarousel類文件(示例文件和“資產(chǎn)”不需要)拖拽到你的工程中狼纬,并且添加QuartzCore framework。

Chameleon Support

變色龍支持

iCarousel is now compatible with the Chameleon iOS-to-Macconversion library (https://github.com/BigZaphod/Chameleon). To use iCarouselwith Chameleon, addUSING_CHAMELEONto your project's preprocessor macros.Check out theChameleon Demoexample project for how to port your iOS iCarousel app to Mac OS usingChameleon - the example demonstrates how to run the No Nib iPhone example onMac OS using Chameleon. Note that tap-to-center doesn't currently work, andscrolling must be done using a two-fingered scroll gesture, not click-and-drag(both of these are due to features/limitations of the ChameleonUIGestureRecognizer implementation).

iCarousel現(xiàn)在與變色龍iOS-to-Mac轉(zhuǎn)換庫兼容(https://github.com/BigZaphod/Chameleon)骂际。在使用帶有變色龍的iCarousel時(shí)疗琉,在你工程的預(yù)處理程序宏定義中添加USING_CHAMELEON 。如何使用變色龍把你的iOS iCarousel app整體搬移到Mac OS請(qǐng)查看Chameleon示例工程歉铝。注意没炒,tap-to-center目前是不工作的,并且,滾動(dòng)必須使用2個(gè)手指滾動(dòng)手勢(shì)才能完成送火,而不是點(diǎn)擊和拖動(dòng)(這些都是由于Chameleon手勢(shì)識(shí)別器的實(shí)現(xiàn)上的特點(diǎn)/限制)。

Carousel Types

Carousel類型

iCarousel supportsthe following built-in display types:

Carousel支持以下內(nèi)置的展示樣式:

iCarouselTypeLinear

線性的

iCarouselTypeRotary

可旋轉(zhuǎn)的

iCarouselTypeInvertedRotary

反向旋轉(zhuǎn)式

iCarouselTypeCylinder

圓柱式

iCarouselTypeInvertedCylinder

反向圓柱式

iCarouselTypeWheel

車輪式

iCarouselTypeInvertedWheel

反向車輪式

iCarouselTypeCoverFlow

封面流

iCarouselTypeCoverflow2

封面流樣式2

iCarouselTypeTimeMachine

時(shí)光機(jī)

iCarouselTypeInvertedTimeMachine

反向時(shí)光機(jī)

You can alsoimplement your own bespoke carousel styles usingiCarouselTypeCustomand thecarousel:itemTransformForOffset:baseTransform:delegate method.

你也可以使用iCarouselTypeCustom和carousel:itemTransformForOffset:baseTransform:代理方法來實(shí)現(xiàn)自己的定制carousel樣式

NOTE: Thedifference betweeniCarouselTypeCoverFlowandiCarouselTypeCoverFlow2types is quite subtle, however the logic foriCarouselTypeCoverFlow2is substantially more complex. If you flick the carousel they arebasically identical, but if you drag the carousel slowly with your finger thedifference should be apparent.iCarouselTypeCoverFlow2is designed to simulate the standard Apple CoverFlow effect as closely aspossible and may change subtly in future in the interests of that goal.

注意:iCarouselTypeCoverFlow和iCarouselTypeCoverFlow2樣式的不同之處很細(xì)微先匪,然而种吸,iCarouselTypeCoverFlow2的邏輯相當(dāng)復(fù)雜。如果你輕彈carousel呀非,他們基本上是一樣的坚俗,但是如果你使用手指慢慢拖動(dòng)carousel,不同點(diǎn)就會(huì)明顯岸裙。iCarouselTypeCoverFlow2是為了模擬盡可能接近標(biāo)準(zhǔn)的蘋果封面流效果而設(shè)計(jì)的猖败,并且可能在未來會(huì)為了這個(gè)目標(biāo)而巧妙地變化。

Properties

屬性

The iCarousel hasthe following properties (note: for Mac OS, substitute NSView for UIView whenusing properties):

iCarousel有以下屬性(注意:對(duì)于Mac OS降允,當(dāng)使用屬性時(shí)用NSView替換UIView)

@property(nonatomic,weak)IBOutletid dataSource;

An object thatsupports the iCarouselDataSource protocol and can provide views to populate thecarousel.

一個(gè)支持iCarouselDataSource協(xié)議且能提供視圖來填充carousel的對(duì)象恩闻。

@property(nonatomic,weak)IBOutletiddelegate;

An object thatsupports the iCarouselDelegate protocol and can respond to carousel events andlayout requests.

一個(gè)支持iCarouselDelegate協(xié)議且可以響應(yīng)iCarousel事件和布局請(qǐng)求的對(duì)象。

@property(nonatomic,assign)iCarouselType type;

Used to switch thecarousel display type (see above for details).

用來變換carousel展示樣式(細(xì)節(jié)見上文)

@property(nonatomic,assign)CGFloatperspective;

Used to tweak theperspective foreshortening effect for the various 3D carousel views. Should bea negative value, less than 0 and greater than -0.01. Values outside of thisrange will yield very strange results. The default is -1/500, or -0.005;

用來稍稍調(diào)整在多種3dcarousel視圖中視覺按照透視法縮短效果的剧董,它應(yīng)該是一個(gè)負(fù)數(shù)幢尚,小于0且大于-0.01,這個(gè)范圍之外的值將會(huì)產(chǎn)生非常奇怪的結(jié)果翅楼。默認(rèn)值是-1/500, or -0.005尉剩。

@property(nonatomic,assign)CGSizecontentOffset;

This property isused to adjust the offset of the carousel item views relative to the center ofthe carousel. It defaults to CGSizeZero, meaning that the carousel items arecentered. Changing this value moves the carousel itemswithoutchanging theirperspective, i.e. the vanishing point moves with the carousel items, so if youmove the carousel items down, itdoes notappear as if you are looking down on the carousel.

這個(gè)屬性用來調(diào)整carousel item views相對(duì)于carousel中心的邊距。它的默認(rèn)值是CGSizeZero毅臊,意思是carousel items是居中的理茎。改變這個(gè)屬性的值來移動(dòng)carousel items而不必改變他們的視覺。消失點(diǎn)隨著carousel items移動(dòng)管嬉,所以皂林,如果你把carousel items移動(dòng)到下邊,如果你在carousel上向下看時(shí)他就不會(huì)出現(xiàn)宠蚂。

@property(nonatomic,assign)CGSizeviewpointOffset;

This property isused to adjust the user viewpoint relative to the carousel items. It has theopposite effect to adjusting the contentOffset, i.e. if you move the viewpointup then the carousel appears to move down. Unlike the contentOffset, moving theviewpoint also changes the perspective vanishing point relative to the carouselitems, so if you move the viewpoint up, it will appear as if you are lookingdown on the carousel.

這個(gè)屬性用來調(diào)整相對(duì)于carousel items的用戶視點(diǎn)式撼,它有一個(gè)副作用就是調(diào)整contentOffset。如果你向上移動(dòng)視點(diǎn)求厕,然后carousel顯示是向下移動(dòng)著隆。與contentOffset不同,移動(dòng)視點(diǎn)也會(huì)改變和carousel items有關(guān)的視角消失點(diǎn)呀癣,所以如果你向上移動(dòng)視點(diǎn)美浦,他就會(huì)像你在carousel上向下看一樣出現(xiàn)。

@property(nonatomic,assign)CGFloatdecelerationRate;

The rate at whichthe carousel decelerates when flicked. Higher values mean slower deceleration.The default value is 0.95. Values should be in the range 0.0 (carousel stopsimmediately when released) to 1.0 (carousel continues indefinitely withoutslowing down, unless it reaches the end).

這個(gè)率用于carousel被快速輕擊時(shí)carousel減速率项栏。值越大表示減速越慢浦辨。默認(rèn)值是0.95.值應(yīng)該在0.0(設(shè)置為這個(gè)值時(shí),carousel被釋放時(shí)立即停止?jié)L動(dòng))和1.0(設(shè)置為這個(gè)值時(shí)沼沈,carousel繼續(xù)無限滾動(dòng)而不減速流酬,直到它到達(dá)底部)之間币厕。

@property(nonatomic,assign)BOOL bounces;

Sets whether thecarousel should bounce past the end and return, or stop dead. Note that thishas no effect on carousel types that are designed to wrap, or where thecarouselShouldWrap delegate method returns YES.

設(shè)置carousel在超出底部和返回時(shí)是否應(yīng)該彈跳,或者是停止并掛掉芽腾。注意旦装,在carousel樣式設(shè)置為纏繞樣式時(shí)或者carouselShouldWrap代理方法返回為yes時(shí),這個(gè)屬性不起作用摊滔。

@property(nonatomic,assign)CGFloatbounceDistance;

The maximumdistance that a non-wrapped carousel will bounce when it overshoots the end.This is measured in multiples of the itemWidth, so a value of 1.0 would meansthe carousel will bounce by one whole item width, a value of 0.5 would be halfan item's width, and so on. The default value is 1.0;

一個(gè)非包裹樣式的carousel在超過底部時(shí)將彈跳的最大距離阴绢。這個(gè)用itemWidth的倍數(shù)來衡量的,所以1.0這個(gè)值意味著彈跳一整個(gè)item的寬度艰躺,0.5這個(gè)值是一個(gè)item寬度的一半呻袭,以此類推。默認(rèn)值是1.0.

@property(nonatomic,assign,getter=isScrollEnabled)BOOL scrollEnabled;

Enables anddisables user scrolling of the carousel. The carousel can still be scrolledprogrammatically if this property is set to NO.

使能或者禁止用戶滾動(dòng)carousel腺兴。如果這個(gè)值被設(shè)為no左电,carousel仍然可以以編程方式被滾動(dòng)。

@property(nonatomic,readonly,getter=isWrapEnabled)BOOL wrapEnabled;

Returns YES ifwrapping is enabled and NO if it isn't. This property is read only. If you wishto override the default value, implement thecarousel:valueForOption:withDefault:delegate method and return a value foriCarouselOptionWrap.

如果打包被使能的話含长,返回yes券腔,如果不是返回no。這個(gè)屬性是只讀的拘泞。如果你想重寫這個(gè)默認(rèn)值纷纫,實(shí)現(xiàn)carousel:valueForOption:withDefault:方法且給iCarouselOptionWrap返回一個(gè)值。

@property(nonatomic,readonly)NSIntegernumberOfItems;

The number of itemsin the carousel (read only). To set this, implement thenumberOfItemsInCarousel:dataSource method. Note that not all of these item views will be loaded orvisible at a given point in time - the carousel loads item views on demand asit scrolls.

carousel中items的數(shù)量(只讀)陪腌,要設(shè)置他的話辱魁,實(shí)現(xiàn)numberOfItemsInCarousel:這個(gè)數(shù)據(jù)源方法。注意诗鸭,所有這些item views在一個(gè)給定的時(shí)間點(diǎn)將會(huì)被加載或者可見-carousel當(dāng)它滾動(dòng)的時(shí)候經(jīng)要求加載item views染簇。

@property(nonatomic,readonly)NSIntegernumberOfPlaceholders;

The number ofplaceholder views to display in the carousel (read only). To set this,implement thenumberOfPlaceholdersInCarousel:dataSource method.

在carousel中展示的占位視圖的數(shù)量(只讀)。要設(shè)置他强岸,實(shí)現(xiàn)一下numberOfPlaceholdersInCarousel:這個(gè)數(shù)據(jù)源方法锻弓。

@property(nonatomic,readonly)NSIntegernumberOfVisibleItems;

The maximum numberof carousel item views to be displayed concurrently on screen (read only). Thisproperty is important for performance optimisation, and is calculatedautomatically based on the carousel type and view frame. If you wish tooverride the default value, implement thecarousel:valueForOption:withDefault:delegate method and return a value for iCarouselOptionVisibleItems.

同時(shí)顯示在屏幕上的carousel itemviews的最大數(shù)量(只讀)。這個(gè)屬性對(duì)執(zhí)行最優(yōu)化很重要蝌箍,且是基于carousel的樣式和視圖的frame被自動(dòng)計(jì)算的青灼。如果你想重寫這個(gè)默認(rèn)值,實(shí)現(xiàn)一下carousel:valueForOption:withDefault:(原文件中沒有找到這個(gè)方法????工程中使用的是- (NSUInteger)numberOfVisibleItemsInCarousel:(iCarousel *)carousel數(shù)據(jù)源方法)這個(gè)代理方法且給iCarouselOptionVisibleItems返回一個(gè)值妓盲。

@property(nonatomic,strong,readonly)NSArray*indexesForVisibleItems;

An array containingthe indexes of all item views currently loaded and visible in the carousel,including placeholder views. The array contains NSNumber objects whose integervalues match the indexes of the views. The indexes for item views start at zeroand match the indexes passed to the dataSource to load the view, however theindexes for any visible placeholder views will either be negative (less thanzero) or greater than or equal tonumberOfItems. Indexes forplaceholder views in this arraydo notequate to the placeholder view index used with the dataSource.

一個(gè)包含了所有當(dāng)前加載的和在carousel中可見的item views的索引杂拨,包括占位視圖的數(shù)組,這個(gè)數(shù)組包含NSNumber的對(duì)象悯衬,他們的整數(shù)值與視圖的索引匹配弹沽。這些item views的索引從0開始且與加載視圖時(shí)數(shù)據(jù)源傳遞的索引匹配,然而,任何占位視圖的索引將是負(fù)數(shù)或者大于等于numberOfItems策橘。數(shù)組中的placeholder views的索引并不等于數(shù)據(jù)源中使用的占位視圖的索引炸渡。

@property(nonatomic,strong,readonly)NSArray*visibleItemViews;

An array of all theitem views currently displayed in the carousel (read only). This includes anyvisible placeholder views. The indexes of views in this array do not match theitem indexes, however the order of these views matches the order of thevisibleItemIndexes array property, i.e. you can get the item index of a givenview in this array by retrieving the equivalent object from thevisibleItemIndexes array (or, you can just use theindexOfItemView:method, which ismuch easier).

一個(gè)存放當(dāng)前carousel中展示的所有item views的數(shù)組(只讀),它包括任何可見的占位視圖役纹。這個(gè)數(shù)組中視圖的索引并不與item的索引匹配偶摔,然而,這些視圖的順序與visibleItemIndexes數(shù)組屬性中的順序匹配促脉,你可以通過從visibleItemIndexes數(shù)組中去掉??對(duì)應(yīng)的對(duì)象來在這個(gè)數(shù)組中獲取一個(gè)指定視圖的索引(或者,你可以僅僅用indexOfItemView:方法策州,這個(gè)會(huì)更簡單)

@property(nonatomic,strong,readonly)UIView*contentView;

The view containingthe carousel item views. You can add subviews to this view if you want tointersperse them with the carousel items. If you want a view to appear in frontor behind all of the carousel items, you should add it directly to theiCarousel view itself instead. Note that the order of views inside the contentViewis subject to frequent and undocumented change whilst the app is running. Anyviews added to the contentView should have their userInteractionEnabledproperty set to NO to prevent conflicts with iCarousel's touch event handling.

包含carouselitem views的視圖瘸味。你可以增加子視圖如果你想用這些carousel items散置這些視圖。如果你想讓一個(gè)視圖出現(xiàn)在所有carouselitems的前邊或者后邊够挂,你應(yīng)該直接添加它到iCarousel view本身來替代旁仿。注意,在contentView中視圖的順序是受當(dāng)app執(zhí)行時(shí)的頻率和未標(biāo)注的變化決定的孽糖。任何添加到contentView中的視圖應(yīng)該將他們的userInteractionEnabled屬性設(shè)置為no來防止和iCarousel的觸摸時(shí)間處理放生沖突枯冈。

@property(nonatomic,assign)CGFloatscrollOffset;

This is the currentscroll offset of the carousel in multiples of the itemWidth. This value,rounded to the nearest integer, is the currentItemIndex value. You can use thisvalue to position other screen elements while the carousel is in motion. Thevalue can also be set if you wish to scroll the carousel to a particular offsetprogrammatically. This may be useful if you wish to disable the built-ingesture handling and provide your own implementation.

這是以itemWidth的整數(shù)倍來計(jì)算的carousel當(dāng)前的滾動(dòng)偏移量,這個(gè)值办悟,被截取為最接近的整數(shù)尘奏,是currentItemIndex值。當(dāng)carousel運(yùn)動(dòng)中病蛉,你可以使用這個(gè)值定位其他屏幕的元素炫加。這個(gè)值也可以被編程方式設(shè)置如果你想滾動(dòng)carousel到一個(gè)特定的偏移。如果你想禁用內(nèi)置手勢(shì)處理并提供自己的實(shí)現(xiàn)時(shí)铺然,這個(gè)可能有用俗孝。

@property(nonatomic,readonly)CGFloatoffsetMultiplier;

This is the offsetmultiplier used when the user drags the carousel with their finger. It does notaffect programmatic scrolling or deceleration speed. This defaults to 1.0 formost carousel types, but defaults to 2.0 for the CoverFlow-style carousels to compensatefor the fact that their items are more closely spaced and so must be draggedfurther to move the same distance. You cannot set this property directly, butyou can override the default value by implementing thecarouselOffsetMultiplier:delegate method.

這是當(dāng)用戶用手指拖動(dòng)carousel時(shí)偏移量的乘數(shù)。它并不影響編程的滾動(dòng)和減速的速度魄健。對(duì)大多數(shù)carousel樣式這個(gè)默認(rèn)值是1.0赋铝,但是對(duì)CoverFlow-style樣式的carousels默認(rèn)值是2.0,來彌補(bǔ)他們的items在空間上更緊湊沽瘦,所以必須拖拽更遠(yuǎn)來移動(dòng)相同的距離的事實(shí)革骨。你不能直接設(shè)置這個(gè)值,但是可以通過實(shí)現(xiàn)carouselOffsetMultiplier:代理方法來重寫默認(rèn)值其垄。

這個(gè)應(yīng)該是滑動(dòng)一下移動(dòng)的距離苛蒲。

@property(nonatomic,assign)NSIntegercurrentItemIndex;

The index of thecurrently centered item in the carousel. Setting this property is equivalent tocallingscrollToItemAtIndex:animated:with the animated argument set to NO.

當(dāng)前carousel中居中的item的索引,設(shè)置這個(gè)屬性相當(dāng)于調(diào)用scrollToItemAtIndex:animated:方法時(shí)將animated參數(shù)設(shè)置為no绿满。

@property(nonatomic,strong,readonly)UIView*currentItemView;

The currently centered item view in the carousel. Theindex of this view matchescurrentItemIndex.

當(dāng)前carousel中居中的item view臂外。這個(gè)視圖的索引與currentItemIndex匹配。

@property(nonatomic,readonly)CGFloatitemWidth;

The display widthof items in the carousel (read only). This is derived automatically from thefirst view passed in to the carousel using thecarousel:viewForItemAtIndex:reusingView:dataSource method.You can also override this value using thecarouselItemWidth:delegate method, which will alter the space allocated for carousel items(but won't resize or scale the item views).

carousel中展示的items的寬度(只讀)。這是自動(dòng)從使用carousel:viewForItemAtIndex:reusingView:數(shù)據(jù)源方法第一個(gè)傳到carousel中的視圖中繼承來的漏健。你也可以使用carouselItemWidth:代理方法重寫這個(gè)值嚎货,這個(gè)方法會(huì)改變分配給carousel items的空間(但是不會(huì)對(duì)這些item views重寫設(shè)置大小或規(guī)模)。

@property(nonatomic,assign)BOOL centerItemWhenSelected;

When set to YES,tapping any item in the carousel other than the one matching thecurrentItemIndex will cause it to smoothly animate to the center. Tapping thecurrently selected item will have no effect. Defaults to YES.

當(dāng)設(shè)置為yes時(shí)蔫浆,點(diǎn)擊任何在carousel中的item而不是那個(gè)匹配currentItemIndex的視圖殖属,將會(huì)使平滑動(dòng)畫移動(dòng)到居中位置。點(diǎn)擊當(dāng)前被選中的item將沒有效果瓦盛。默認(rèn)值是yes洗显。

@property(nonatomic,assign)CGFloatscrollSpeed;

This is the scrollspeed multiplier when the user flicks the carousel with their finger. Defaultsto 1.0.

這是當(dāng)用戶用手指輕擊carousel時(shí)滾動(dòng)速度乘數(shù)。默認(rèn)值是1.0.

@property(nonatomic,readonly)CGFloattoggle(切換鍵);

This property isused for theiCarouselTypeCoverFlow2carousel transform. It is exposed so that you can implement your ownvariants of the CoverFlow2 style using thecarousel:itemTransformForOffset:baseTransform:delegate method.

這個(gè)屬性用于iCarouselTypeCoverFlow2的carousel變換原环。它是被暴露的以便于你可以使用carousel:itemTransformForOffset:baseTransform:代理方法實(shí)現(xiàn)自己的CoverFlow2樣式變量挠唆。

@property(nonatomic,assign)BOOL stopAtItemBoundary;

By default, thecarousel will come to rest at an exact item boundary when it is flicked. If youset this property to NO, it will stop naturally and then - ifscrollToItemBoundary is set to YES - scroll back or forwards to the nearestboundary.

默認(rèn)情況下,carousel被輕擊時(shí)會(huì)停在一個(gè)準(zhǔn)確的item邊界嘱吗。如果你設(shè)置這個(gè)值為no玄组,他會(huì)自然停止然后-如果scrollToItemBoundary被設(shè)置為yes-滾回或者向前滾動(dòng)到最接近的邊界

@property(nonatomic,assign)BOOL scrollToItemBoundary;

By default wheneverthe carousel stops moving it will automatically scroll to the nearest itemboundary. If you set this property to NO, the carousel will not scroll afterstopping and will stay wherever it is, even if it's not perfectly aligned onthe current index. The exception to this is that if wrapping is disabled andbouncesis set to YES thenregardless of this setting, the carousel will automatically scroll back to thefirst or last item index if it comes to rest beyond the end of the carousel.

默認(rèn)情況下,不管carousel何時(shí)停止移動(dòng)谒麦,他會(huì)自動(dòng)滾動(dòng)到最近的item邊界俄讹。如果你設(shè)置這個(gè)屬性為no,carousel停止后將不會(huì)滾動(dòng)且不管在哪兒他都會(huì)停下來绕德,即使他不是正好對(duì)準(zhǔn)當(dāng)前的索引患膛。有一個(gè)特例,如果打包效果被禁止且bounces唄設(shè)置為yes迁匠,然后剩瓶,不管這個(gè)設(shè)置是什么,carousel會(huì)自動(dòng)滾回第一個(gè)或者最后一個(gè)索引城丧,如果它停下來時(shí)超出了carousel的底部延曙。

@property(nonatomic,assign)BOOL useDisplayLink;

By default on iOSiCarousel will use CADisplayLink instead of NSTimer for animations. On Mac OS,the CVDisplayLink API is used instead. This provides better synchronisationwith the screen refresh, but can occasionally prevents the animation workingproperly when the carousel is combined with other views or animations. If youfind that the carousel is not continuing to move after being dragged, trysetting this property to NO.

在默認(rèn)情況下,在iOS中iCarousel會(huì)使用CADisplayLink而不是NSTimer來進(jìn)行動(dòng)畫亡哄。在Mac OS上枝缔,使用的卻是CVDisplayLinkAPI。這個(gè)在屏幕刷新時(shí)提供了更好的同步效果蚊惯,但是當(dāng)carousel與其他視圖或動(dòng)畫結(jié)合愿卸,有時(shí)會(huì)妨礙動(dòng)畫正常運(yùn)行。如果你發(fā)現(xiàn)carousel被拖動(dòng)后沒有持續(xù)移動(dòng)截型,試一下把這個(gè)屬性置為no趴荸。

@property(nonatomic,assign,getter=isVertical)BOOL vertical;

This propertytoggles whether the carousel is displayed horizontally or vertically on screen.All the built-in carousel types work in both orientations. Switching tovertical changes both the layout of the carousel and also the direction ofswipe detection on screen. Note that custom carousel transforms are notaffected by this property, however the swipe gesture direction will still beaffected.

這個(gè)屬性切換,不管carousel是水平展示還是垂直展示的宦焦。所有內(nèi)嵌的carousel樣式在這兩個(gè)方向上都可以運(yùn)行发钝。切換到垂直將會(huì)改變carousel的布局和屏幕上的切換方向顿涣。注意,自定義的carousel變換不受這個(gè)屬性影響酝豪,但是涛碑,切換手勢(shì)的方向還是會(huì)受影響。

@property(nonatomic,assign)BOOL ignorePerpendicularSwipes;

If YES, thecarousel will ignore swipe gestures that are perpendicular to the orientationof the carousel. So for a horizontal carousel, vertical swipes will not beintercepted. This means that you can have a vertically scrolling scrollViewinside a carousel item view and it will still function correctly. Defaults toYES.

如果為yes,carousel將會(huì)忽略垂直于carousel方向的切換手勢(shì)孵淘。目前蒲障,一個(gè)水平的carousel,垂直切換將不會(huì)被攔截瘫证。這就意味著你可以獲得一個(gè)在carouselitem view里的垂直滾動(dòng)的scrollView切它依然會(huì)正確工作揉阎。默認(rèn)值為yes。

@property(nonatomic,assign)BOOL clipsToBounds;

This is actuallynot a property of iCarousel but is inherited from UIView. It's included herebecause it's a frequently missed feature. Set this to YES to prevent thecarousel item views overflowing their bounds. You can set this property inInterface Builder by ticking the 'Clip Subviews' option. Defaults to NO.

這個(gè)實(shí)際上不是iCarousel的屬性背捌,但是是從UIView繼承來的余黎。它被包含在這里是因?yàn)樗且粋€(gè)經(jīng)常被漏掉的特性。設(shè)置為yes來防止carousel item views超出他們的界限载萌。你可以在InterfaceBuilder里通過點(diǎn)擊'Clip Subviews'選項(xiàng)來設(shè)置這個(gè)屬性。默認(rèn)值是no巡扇。

Methods

方法

The iCarousel classhas the following methods (note: for Mac OS, substitute NSView for UIView inmethod arguments):

iCarousel類有以下方法(注意:對(duì)于Mac OS扭仁,在方法的參數(shù)中用NSView來代替UIView)

-(void)scrollToItemAtIndex:(NSInteger)indexanimated:(BOOL)animated;

This will centerthe carousel on the specified item, either immediately or with a smoothanimation. For wrapped carousels, the carousel will automatically determine theshortest (direct or wraparound) distance to scroll. If you need to control thescroll direction, or want to scroll by more than one revolution, use thescrollByNumberOfItems method instead.

這個(gè)方法會(huì)使carousel居中在一個(gè)特定的item,立即或者使用一個(gè)平滑的動(dòng)畫厅翔。對(duì)于打包的carousels乖坠,carousel將會(huì)自動(dòng)決定滾動(dòng)的最短(直線會(huì)或者包著的)距離。如果你需要控制這個(gè)滾動(dòng)的方向刀闷,或者想滾動(dòng)多于一個(gè)分辨率熊泵,使用scrollByNumberOfItems這個(gè)方法。

-(void)scrollToItemAtIndex:(NSInteger)indexduration:(NSTimeInterval)scrollDuration;

This method allowsyou to control how long the carousel takes to scroll to the specified index.

這個(gè)方法允許你來控制carousel使用多長時(shí)間來滾動(dòng)到特定的索引甸昏。

-(void)scrollByNumberOfItems:(NSInteger)itemCountduration:(NSTimeInterval)duration;

This method allowsyou to scroll the carousel by a fixed distance, measured in carousel itemwidths. Positive or negative values may be specified for itemCount, dependingon the direction you wish to scroll. iCarousel gracefully handles boundsissues, so if you specify a distance greater than the number of items in thecarousel, scrolling will either be clamped when it reaches the end of thecarousel (if wrapping is disabled) or wrap around seamlessly.

這個(gè)方法允許你使用一個(gè)固定的距離滾動(dòng)carousel顽分,以carousel的item寬度來衡量。整數(shù)或負(fù)數(shù)可能由itemCount來具體確定施蜜,取決于你希望滾動(dòng)的方向卒蘸。iCarousel很好的處理了邊界問題,所以如果你指定了一個(gè)大于carousel中items數(shù)量的值翻默,滾動(dòng)或者在到達(dá)carousel底部時(shí)被夾緊(如果打包被禁止)缸沃,或者無停頓地包裹。

-(void)scrollToOffset:(CGFloat)offsetduration:(NSTimeInterval)duration;

This works the same way asscrollToItemAtIndex:, but allows you toscroll to a fractional offset. This may be useful if you wish to achieve a veryprecise animation effect. Note that if thescrollToItemBoundaryproperty is set to YES, the carousel will automatically scroll to thenearest item index after you call this method. anyway.

這個(gè)方法工作起來和scrollToItemAtIndex:方法一樣修械,但是允許你移動(dòng)到一個(gè)微小的偏移趾牧。如果你想達(dá)到一個(gè)非常準(zhǔn)確的動(dòng)畫效果時(shí)這個(gè)可能有用。注意肯污,如果scrollToItemBoundary屬性被設(shè)置為yes翘单,當(dāng)你調(diào)用這個(gè)方法之后carousel會(huì)自動(dòng)滾動(dòng)到最近的item索引吨枉。

-(void)scrollByOffset:(CGFloat)offsetduration:(NSTimeInterval)duration;

This works the sameway asscrollByNumberOfItems:, but allows you toscroll by a fractional number of items. This may be useful if you wish toachieve a very precise animation effect. Note that if thescrollToItemBoundaryproperty is set to YES, the carousel will automatically scroll to thenearest item index after you call this method anyway.

這個(gè)方法作用與scrollByNumberOfItems:方法一樣,但是允許你滾動(dòng)到一個(gè)微小數(shù)量的items县恕。如果你想達(dá)到一個(gè)非常準(zhǔn)確的動(dòng)畫效果時(shí)可能有用东羹。注意,如果scrollToItemBoundary屬性被設(shè)置為yes忠烛,在你調(diào)用這個(gè)方法后carousel無論如何會(huì)自動(dòng)滾動(dòng)到最近一個(gè)item索引属提。

(這個(gè)應(yīng)該是滾動(dòng)幾個(gè)items)

-(void)reloadData;

This reloads allcarousel views from the dataSource and refreshes the carousel display.

這個(gè)方法重新從數(shù)據(jù)源加載carousel視圖并刷新carousel的顯示。

-(UIView*)itemViewAtIndex:(NSInteger)index;

Returns the visibleitem view with the specified index. Note that the index relates to the positionin the carousel, and not the position in thevisibleItemViewsarray, which may bedifferent. Pass a negative index or one greater than or equal tonumberOfItemsto retrieveplaceholder views. The method only works for visible item views and will returnnil if the view at the specified index has not been loaded, or if the index isout of bounds.

返回帶有指定索引的可見的item視圖美尸。注意冤议,這個(gè)索引和carousel的位置有關(guān),且不是在visibleItemViews數(shù)組中的位置师坎,這可能是不一樣的恕酸。傳遞一個(gè)賦值或者一個(gè)大于等于numberOfItems的整數(shù)來取回占位視圖。這個(gè)方法只有在是可見視圖且情況下才工作胯陋,且如果這個(gè)在指定索引處的視圖還沒被加載時(shí)蕊温,或者這個(gè)索引超出范圍時(shí),將返回空遏乔。

-(NSInteger)indexOfItemView:(UIView*)view;

The index for agiven item view in the carousel. Works for item views and placeholder views,however placeholder view indexes do not match the ones used by the dataSourceand may be negative (seeindexesForVisibleItemsproperty above for more details). This method only works for visible itemviews and will return NSNotFound for views that are not currently loaded. For alist of all currently loaded views, use thevisibleItemViewsproperty.

這個(gè)是carousel中指定item view的索引义矛。對(duì)item views和placeholder views起作用,但是盟萨,placeholder view索引并不和數(shù)據(jù)源中的索引匹配凉翻,且有可能是負(fù)值。(查看上面indexesForVisibleItems屬性介紹的細(xì)節(jié))捻激。這個(gè)方法只對(duì)可見的item views起作用且對(duì)目前沒有加載的視圖會(huì)返回NSNotFound制轰。對(duì)于一列所有加載的視圖,使用visibleItemViews屬性胞谭。

-(NSInteger)indexOfItemViewOrSubview:(UIView*)view

This method givesyou the item index of either the view passed or the view containing the viewpassed as a parameter. It works by walking up the view hierarchy starting withthe view passed until it finds an item view and returns its index within thecarousel. If no currently-loaded item view is found, it returns NSNotFound.This method is extremely useful for handling events on controls embedded withinan item view. This allows you to bind all your item controls to a single actionmethod on your view controller, and then work out which item the control thattriggered the action was related to. You can see an example of this techniquein theControls Demoexample project.

這個(gè)方法給你或者是傳遞的視圖或者是包含有作為參數(shù)的視圖的視圖的item索引垃杖。它通過以傳遞進(jìn)來的視圖為開始,向上遍歷視圖層級(jí)韭赘,直到找到一個(gè)itemview并返回他在carousel中的索引缩滨。如果沒有找到當(dāng)前加載的item view,它會(huì)返回NSNotFound泉瞻。這個(gè)方法對(duì)處理一個(gè)item view內(nèi)嵌的事件控制極其有用脉漏。它允許你綁定你的在控制器中控制單一行為方法的item,且會(huì)找出控制觸發(fā)相關(guān)行為的item袖牙。你可以看一下在Controls Demoexample工程中這個(gè)技術(shù)的例子侧巨。

看到這兒了!

-(CGFloat)offsetForItemAtIndex:(NSInteger)index;

Returns the offsetfor the specified item index in multiples ofitemWidthfrom the centerposition. This is the same value used for calculating the view transform andalpha, and can be used to customise item views based on their position in thecarousel. This value can be expected to change for each view whenever thecarouselDidScroll:delegate method is called.

返回以itemWidth整數(shù)倍來記的指定的item索引處的偏移量

-(void)removeItemAtIndex:(NSInteger)indexanimated:(BOOL)animated;

This removes anitem from the carousel. The remaining items will slide across to fill the gap.Note that the data source is not automatically updated when this method iscalled, so a subsequent call to reloadData will restore the removed item.

-(void)insertItemAtIndex:(NSInteger)indexanimated:(BOOL)animated;

This inserts anitem into the carousel. The new item will be requested from the dataSource, somake sure that the new item has been added to the data source data beforecalling this method, or you will get duplicate items in the carousel, or otherweirdness.

-(void)reloadItemAtIndex:(NSInteger)indexanimated:(BOOL)animated;

This method willreload the specified item view. The new item will be requested from thedataSource. If the animated argument is YES, it will cross-fade from the old tothe new item view, otherwise it will swap instantly.

Protocols

協(xié)議

The iCarouselfollows the Apple convention for data-driven views by providing two protocolinterfaces, iCarouselDataSource and iCarouselDelegate. The iCarouselDataSourceprotocol has the following required methods (note: for Mac OS, substituteNSView for UIView in method arguments):

-(NSUInteger)numberOfItemsInCarousel:(iCarousel*)carousel;

Return the numberof items (views) in the carousel.

返回carousel中界面的數(shù)量

-(UIView*)carousel:(iCarousel*)carouselviewForItemAtIndex:(NSUInteger)index reusingView:(UIView*)view;

Return a view to bedisplayed at the specified index in the carousel. ThereusingViewargument works likea UIPickerView, where views that have previously been displayed in the carouselare passed back to the method to be recycled. If this argument is not nil, youcan set its properties and return it instead of creating a new view instance,which will slightly improve performance. Unlike UITableView, there is noreuseIdentifier for distinguishing between different carousel view types, so ifyour carousel contains multiple different view types then you should justignore this parameter and return a new view each time the method is called. Youshould ensure that each time thecarousel:viewForItemAtIndex:reusingView:method is called, it either returns the reusingView or a brand new viewinstance rather than maintaining your own pool of recyclable views, asreturning multiple copies of the same view for different carousel item indexesmay cause display issues with the carousel.

返回一個(gè)在carousel中要在指定索引處顯示的視圖,reusingView參數(shù)的作用就像UIPickerView鞭达,之前在carousel中展示過的界面被傳遞到方法中來循環(huán)使用司忱。如果這個(gè)參數(shù)不是空皇忿,你可以設(shè)置它的屬性并返回它而不是創(chuàng)建一個(gè)新的視圖實(shí)例,這樣可以稍改善性能坦仍。與UITableView不同鳍烁,這里沒有重用id來區(qū)分不同的carousel界面類型。

所以如果你的carousel包含多個(gè)不同的視圖類型繁扎,那么每次這個(gè)方法被調(diào)用的時(shí)候幔荒,你應(yīng)該只是忽略這個(gè)參數(shù)并返回一個(gè)新的視圖。你應(yīng)該確認(rèn)carousel:viewForItemAtIndex:reusingView:方法每次被調(diào)用時(shí)梳玫,它要么返回重用的視圖爹梁,要么返回一個(gè)新的視圖實(shí)例而不是保留你自己的循環(huán)視圖池,因?yàn)闉椴煌腸arousel界面索引返回多個(gè)相同視圖的復(fù)制品可能造成顯示問題提澎。

TheiCarouselDataSource protocol has the following optional methods:

-(NSUInteger)numberOfPlaceholdersInCarousel:(iCarousel*)carousel;

Returns the numberof placeholder views to display in the carousel. Placeholder views are intendedto be used when the number of items in the carousel is too few to fill thecarousel width, and you wish to display something in the empty space. They movewith the carousel and behave just like any other carousel item, but they do notcount towards the numberOfItems value, and cannot be set as the currentlyselected item. Placeholders are hidden when wrapping is enabled. Placeholdersappear on either side of the carousel items. For n placeholder views, the firstn/2 items will appear to the left of the item views and the next n/2 willappear to the right. You can have an odd number of placeholders, in which casethe carousel will be asymmetrical.

返回在carousel中展示的占位視圖姚垃。占位視圖用來當(dāng)carousel中界面太少而不能填滿carousel的寬度,并且你希望在空白的地方顯示一些東西時(shí)使用盼忌。它們隨著carousel移動(dòng)并且像其他carousel界面一樣運(yùn)行积糯,但是它們不占numberOfItems數(shù)量耕肩,且不能被設(shè)置為當(dāng)前選中的界面允悦。當(dāng)打包屬性被使能時(shí)占位視圖被隱藏瘩绒。占位視圖或者顯示在carousel界面的任何一方肠鲫。對(duì)于n個(gè)占位視圖,前n/2個(gè)界面將會(huì)出現(xiàn)在界面視圖的左邊泳梆,下一個(gè)n/2個(gè)界面會(huì)出現(xiàn)在右邊。你可以有奇數(shù)個(gè)占位視圖,這種情況下carousel會(huì)是不對(duì)稱的偿荷。

-(UIView*)carousel:(iCarousel*)carouselplaceholderViewAtIndex:(NSUInteger)index reusingView:(UIView*)view;

Return a view to bedisplayed as the placeholder view. Works the same way ascarousel:viewForItemAtIndex:reusingView:. PlaceholderreusingViews are stored in a separate pool to the reusingViews used for regularcarousel, so it's not a problem if your placeholder views are different to theitem views.

TheiCarouselDelegate protocol has the following optional methods:

-(void)carouselWillBeginScrollingAnimation:(iCarousel*)carousel;

This method iscalled whenever the carousel will begin an animated scroll. This can betriggered programatically or automatically after the user finishes scrollingthe carousel, as the carousel re-aligns itself.

-(void)carouselDidEndScrollingAnimation:(iCarousel*)carousel;

This method iscalled when the carousel ends an animated scroll.

-(void)carouselDidScroll:(iCarousel*)carousel;

This method iscalled whenever the carousel is scrolled. It is called regardless of whetherthe carousel was scrolled programatically or through user interaction.

-(void)carouselCurrentItemIndexDidChange:(iCarousel*)carousel;

This method iscalled whenever the carousel scrolls far enough for the currentItemIndexproperty to change. It is called regardless of whether the item index wasupdated programatically or through user interaction.

-(void)carouselWillBeginDragging:(iCarousel*)carousel;

This method iscalled when the user begins dragging the carousel. It will not fire if the usertaps/clicks the carousel, or if the carousel is scrolled programmatically.

-(void)carouselDidEndDragging:(iCarousel*)carousel willDecelerate:(BOOL)decelerate;

This method iscalled when the user stops dragging the carousel. The willDecelerate parameterindicates whether the carousel is travelling fast enough that it needs todecelerate before it stops (i.e. the current index is not necessarily the oneit will stop at) or if it will stop where it is. Note that even ifwillDecelerate is NO, the carousel will still scroll automatically until italigns exactly on the current index. If you need to know when it has stoppedmoving completely, use the carouselDidEndScrollingAnimation delegate method.

-(void)carouselWillBeginDecelerating:(iCarousel*)carousel;

This method iscalled when the carousel starts decelerating. it will typically be calledimmediately after the carouselDidEndDragging:willDecelerate: method, assumingwillDecelerate was YES.

-(void)carouselDidEndDecelerating:(iCarousel*)carousel;

This method iscalled when the carousel finishes decelerating and you can assume that thecurrentItemIndex at this point is the final stopping value. Unlike previousversions, the carousel will now stop exactly on the final index position inmost cases. The only exception is on non-wrapped carousels with bounce enabled,where, if the final stopping position is beyond the end of the carousel, thecarousel will then scroll automatically until it aligns exactly on the endindex. For backwards compatibility, the carousel will always callscrollToItemAtIndex:animated:after it finishes decelerating. If you need to know for certain when thecarousel has stopped moving completely, use thecarouselDidEndScrollingAnimationdelegate method.

-(CGFloat)carouselItemWidth:(iCarousel*)carousel;

Returns the widthof each item in the carousel - i.e. the spacing for each item view. If themethod is not implemented, this defaults to the width of the first item viewthat is returned by thecarousel:viewForItemAtIndex:reusingView:dataSource method. This method should only be used to crop or pad itemviews if the views returned fromcarousel:viewForItemAtIndex:reusingView:are not correct (e.g. if the views are differing sizes, or include a dropshadow or outer glow in their background image that affects their size) - ifyou just want to space out the views a bit then it's better to use theiCarouselOptionSpacingvalue instead.

-(CATransform3D)carousel:(iCarousel*)carouselitemTransformForOffset:(CGFloat)offset baseTransform:(CATransform3D)transform;

This method can beused to provide a custom transform for each carousel view. The offset argumentis the distance of the view from the middle of the carousel. The currentlycentred item view would have an offset of 0.0, the one to the right would havean offset value of 1.0, the one to the left an offset value of -1.0, and so on.To implement the linear carousel style, you would therefore simply multiply theoffset value by the item width and use it as the x value of the transform. Thismethod is only called if the carousel type is iCarouselTypeCustom.

-(CGFloat)carousel:(iCarousel*)carouselvalueForOption:(iCarouselOption)option withDefault:(CGFloat)value;

This method is usedto customise the parameters of the standard carousel types. By implementingthis method, you can tweak options such as the number of items displayed in acircular carousel, or the amount of tilt in a coverflow carousel, as well aswhether the carousel should wrap and if it should fade out at the ends, etc.For any option you are not interested in tweaking, just return the defaultvalue. The meaning of these options is listed below underiCarouselOption values. Check theOptions Demofor an advanced example of using this method.

-(void)carousel:(iCarousel*)carousel didSelectItemAtIndex:(NSInteger)index;

This method willfire if the user taps any carousel item view (not including placeholder views),including the currently selected view. This method will not fire if the usertaps a control within the currently selected view (i.e. any view that is asubclass of UIControl).

-(BOOL)carousel:(iCarousel*)carouselshouldSelectItemAtIndex:(NSInteger)index;

This method willfire if the user taps any carousel item view (not including placeholder views),including the currently selected view. The purpose of a method is to give youthe opportunity to ignore a tap on the carousel. If you return YES from themethod, or don't implement it, the tap will be processed as normal and thecarousel:didSelectItemAtIndex:method will be called. If you return NO, the carousel will ignore the tapand it will continue to propagate up the view hierarchy. This is a good way toprevent the carousel intercepting tap events intended for processing by anotherview.

iCarouselOptionvalues

These are the tweakableoptions for standard carousels. Check theOptions Demofor an example ofthe effect that these parameters have.

iCarouselOptionWrap

A booleanindicating whether the carousel should wrap when it scrolls to the end. ReturnYES if you want the carousel to wrap around when it reaches the end, and NO ifyou want it to stop. Generally, circular carousel types will wrap by defaultand linear ones won't. Don't worry that the return type is a floating pointvalue - any value other than 0.0 will be treated as YES.

iCarouselOptionShowBackfaces

For some carouseltypes, e.g. iCarouselTypeCylinder, the rear side of some views can be seen(iCarouselTypeInvertedCylinder now hides the back faces by default). If youwish to hide the backward-facing views you can return NO for this option. Tooverride the default back-face hiding for the iCarouselTypeInvertedCylinder,you can return YES. This option may also be useful for custom carouseltransforms that cause the back face of views to be displayed.

iCarouselOptionOffsetMultiplier

The offsetmultiplier to use when the user drags the carousel with their finger. It doesnot affect programmatic scrolling or deceleration speed. This defaults to 1.0for most carousel types, but defaults to 2.0 for the CoverFlow-style carouselsto compensate for the fact that their items are more closely spaced and so mustbe dragged further to move the same distance.

iCarouselOptionVisibleItems

This is the maximumnumber of item views (including placeholders) that should be visible in thecarousel at once. Half of this number of views will be displayed to either sideof the currently selected item index. Views beyond that will not be loadeduntil they are scrolled into view. This allows for the carousel to contain avery large number of items without adversely affecting performance. iCarouselchooses a suitable default value based on the carousel type, however you maywish to override that value using this property (e.g. if you have implemented acustom carousel type).

iCarouselOptionCount

The number of itemsto be displayed in the Rotary, Cylinder and Wheel transforms. Normally this iscalculated automatically based on the view size and number of items in thecarousel, but you can override this if you want more precise control of thecarousel appearance. This property is used to calculate the carousel radius, soanother option is to manipulate the radius directly.

iCarouselOptionArc

The arc of theRotary, Cylinder and Wheel transforms (in radians). Normally this defaults to2*M_PI (a complete circle) but you can specify a smaller value, so for examplea value of M_PI will create a half-circle or cylinder. This property is used tocalculate the carousel radius and angle step, so another option is tomanipulate those values directly.

iCarouselOptionRadius

The radius of theRotary, Cylinder and Wheel transforms in pixels/points. This is usuallycalculated so that the number of visible items exactly fits into the specifiedarc. You can manipulate this value to increase or reduce the item spacing (andthe radius of the circle).

iCarouselOptionAngle

The angular stepbetween each item in the Rotary, Cylinder and Wheel transforms (in radians).Manipulating this value without changing the radius will cause a gap at the endof the carousel or cause the items to overlap.

iCarouselOptionTilt

The tilt applied tothe non-centered items in the CoverFlow, CoverFlow2 and TimeMachine carouseltypes. This value should be in the range 0.0 to 1.0.

iCarouselOptionSpacing

The spacing betweenitem views. This value is multiplied by the item width (or height, if thecarousel is vertical) to get the total space between each item, so a value of1.0 (the default) means no space between views (unless the views alreadyinclude padding, as they do in many of the example projects).

iCarouselOptionFadeMin

iCarouselOptionFadeMax

iCarouselOptionFadeRange

These three optionscontrol the fading out of carousel item views based on their offset from thecurrently centered item. FadeMin is the minimum negative offset an item viewcan reach before it begins to fade. FadeMax is the maximum positive offset aview can reach before if begins to fade. FadeRange is the distance the item canmove between the point at which it begins to fade and the point at which itbecomes completely invisible.

Detecting Taps onItem Views

There are two basicapproaches to detecting taps on views in iCarousel on iOS. The first approachis to simply use thecarousel:didSelectItemAtIndex:delegate method, which fires every time an item is tapped. If you are onlyinterested in taps on the currently centered item, you can compare thecurrentItemIndexproperty againstthe index parameter of this method.

Alternatively, ifyou want a little more control you can supply a UIButton or UIControl as theitem view and handle the touch interactions yourself. See theButtons Demoexample project foran example of how this is done (doesn't work on Mac OS; see below).

You can also nestUIControls within your item views and these will receive touches as expected(see theControls Demoexample project for an example).

If you wish todetect other types of interaction such as swipes, double taps or long presses,the simplest way is to attach a UIGestureRecognizer to your item view or itssubviews before passing it to the carousel.

Note that taps andgestures will be ignored on any item view except the currently selected one,unless you set thecenterItemWhenSelectedproperty to NO.

On Mac OS there isno easy way to embed controls within iCarousel item views currently. You cannotjust supply an NSButton as or inside your item view because the transformsapplied to the item views mean that hit detection doesn't work properly. I'minvestigating possible solutions to this (if you know a good way to fix this,please get in touch, or fork the project on github).

Example projects

iCarousel includesa number of example projects to help you get started. Here is a lift and briefdescription for each:

BasiciOSExample

This is a verysimple example for iOS that demonstrates setting up a carousel with theiCarouselCoverflow2 type.

iOSDemo

This is a morecomplex iOS demo app that shows off all the different carousel types andadditional features such as dynamic insertion/deletion of items.

MacDemo

This is a Mac OSport of the iOS Demo example, which replicates all the same functionality.

ButtonsDemo

This example demonstrateshow to use UIButtons as your item views on iOS and correctly handle the events.

ControlsDemo

This exampledemonstrates how to nest controls within your item views on iOS and correctlyhandle the events, as well as how to load complex item views from a nib fileinstead of generating them in code.

MultipleCarousels

This exampledemonstrates how to use multiple carousels within a single view controller.

NoNibDemo

This exampledemonstrates how to set up iCarousel without using a nib file on iOS.

StoryboardDemo

This exampledemonstrates how to set up iCarousel using Storyboards on iOS 5 and above.

OffsetsDemo

This exampledemonstrates how to use thecontentOffsetandviewpointOffsetproperties, and the effect they have.

OptionsDemo

This example demonstrateshow to customise the appearance of each carousel type using the iCarouselOptionAPI.

DynamicViewReflections

This exampledemonstrates how to use the ReflectionView class(https://github.com/nicklockwood/ReflectionView) to dynamically generatereflections for your item views. This is applicable to item views that containsubviews or controls. For item views that are just images, it's better to usethe approach shown in theDynamic ImageEffectsexample.

DynamicImageEffects

This exampledemonstrates how to use the FXImageView class(https://github.com/nicklockwood/FXImageView) to dynamically generatereflections and drop shadows for your carousel images.

DynamicDownloads

This exampledemonstrates how to use the AsyncImageView class(https://github.com/nicklockwood/AsyncImageView) to dynamically download remoteimages and display them in a carousel without blocking the main thread ornegatively affecting performance.

Downloads&Effects

This exampledemonstrates how to use the FXImageView class(https://github.com/nicklockwood/FXImageView) to download images on the fly andapply reflections and drop shadows to them in real time.

FAQ

Q.I upgrade to thenewversion of iCarouselandit brokemyproject,howdoIgetthe old one back?

A.Everyprevious release of iCarouselistaggedasa separatedownload on github-lookinthe tags tab.

Q.CanIuseiCarousel without a nib file?

A.Yes,checkoutthe*NoNibDemo*forhow tosetup iCarousel without nibs

Q.CanIuseiCarouselwithaStoryboard?

A.Yes,thisispretty much thesameasusingitwitha nib file.Checkoutthe*StoryboardDemo*to see how it's done.

Q. How do Iprevent iCarousel item views from overflowing their bounds?

A. Set the`clipsToBounds` property to YES on your iCarousel view. You can set thisproperty in Interface Builder by ticking the 'ClipSubviews' option.

Q. I'm gettingweird issueswhereviews turn up at the wrong pointsinthe carousel.What's going on?

A. You'reprobably recycling viewsinyour`carousel:viewForItemAtIndex:reusingView:`usingthe`reusingView`parameter without setting the view contentseach time.Studythe demo app more closelyandmake sure you aren't doing all your itemview setup in the wrong place.

Q. I'm loading50imagesinmycarouselandI keep runningoutof memory.Howcan I fix it?

A.Thetrickisto load the viewson a background threadasthe carouselisscrolling instead of loading them allinadvance.Checkoutthe*DynamicDownloads*exampleforhow todothisusingtheAsyncImageViewlibrary.Theexampleisusingremote imageURLs,but the exact same approach will work justaswellforlocally hosted imagesinyour app-just createlocalfileURLsusing`[NSURL fileUrlWithPath:...]`.

Q.CanIusemultiple carouselsinthe same viewcontroller?

A.Yes,checkoutthe*MultipleCarousels*exampleforhow todothis.

Q.I can't figure out how to use iCarousel inmy project, is there a simple example?

A. Yes, check outthe *Basic iOS Example* project for a bare-bones implementation. If you'restillnotclear what's going on, read up about howUITableView works, and once you understand that, iCarousel will make moresense.

Q. In theiCarouselTypeCylinder carousel, the back-side of the item views is visible. Howcan I hide these views?

A. You can eitherreturn NO as the value for the `iCarouselOptionShowBackfaces` option, or setthe `view.layer.doubleSided` property of your item views to `NO` to hide themwhen they are facing backwards.

Q. What is the`reusingView` property for in the `carousel:viewForItemAtIndex:reusingView:`dataSource method?

A. You canimprove iCarousel performance by recycling item views when they move offscreeninstead of creating a new one each time it's needed.Checkifthisvalueisnil,andifnotyou can re-usethisview instead of creating anewone.Notehowever that the view will still haveany subviewsorproperties you addedwhenit was first created,so be carefulnotto introduce leaksbyre-adding thoseviews each time.Youmay find it's easier and safer to ignorethis paramater and create a fresh view each time if you'renotsure what you are doing.

Q.Ifthe viewsinmycarousel all have completely differentlayouts,should I stillusethe`reusingView`parameter?

A.Probablynot,andunlessyou have hundreds of viewsinyour carousel,it's unlikely to be worth the trouble.

Q. I'musingiCarouselTypeLinear.Howcan I make it behave more like aUIScrollViewwithpaging enabled?

A.IfyousetdecelerationRate to zerotheniCarousel will more closely emulate thefeel of aUIScrollView.Ifthat's still notclose enough, consider using my SwipeView library instead(https://github.com/nicklockwood/SwipeView) which is very similar to iCarousel,but based on a UIScrollView.

Q. I want mycarousel items to have a real reflection, but the reflection in the examples isjust drawn on. How can I render reflections dynamically?

A. iCarouseldoesn't have built-inreflectionsupport,but you canusesome additional libraries todothis.Checkoutthe*DynamicViewReflections*and*DynamicImageEffects*examples.

Q.I want to download a bunch of images on theflyanddisplay theminmycarousel.Howcan Idothat?

A.Downloadingimages asynchronouslyanddisplaying themisquite complex.YoucanusemyAsyncImageViewlibrary to simplify the process.Checkoutthe*DynamicDownloads*example.

Q.WhatifI want todownload images on the fly*and*add a reflection?CanI combine theReflectionViewandAsyncImageViewclasses?

A.Technicallyyes,butifyou aredownloading images you'd be better off using the FXImageView class instead ofReflectionView. Check out the *Downloads & Reflections* example.

Q. The edges ofmy item views look jaggy. Is there any way to smooth/antialias them?

A. If you include(at least) a single pixel of transparent space around the edge of your itemview images then iOS will smooth them automatically. This is because iOSautomatically antialiases the pixels inside images, but doesn't antialias theedges of views.Evenifyour item viewsare a flat color,it's worth addinga background image of the same color to the views in order to get the smoothingeffect.

原文地址: https://www.binpress.com/app/icarousel/614

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市唠椭,隨后出現(xiàn)的幾起案子跳纳,更是在濱河造成了極大的恐慌,老刑警劉巖贪嫂,帶你破解...
    沈念sama閱讀 206,378評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件寺庄,死亡現(xiàn)場離奇詭異,居然都是意外死亡力崇,警方通過查閱死者的電腦和手機(jī)斗塘,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,356評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來亮靴,“玉大人馍盟,你說我怎么就攤上這事〖氲酰” “怎么了贞岭?”我有些...
    開封第一講書人閱讀 152,702評(píng)論 0 342
  • 文/不壞的土叔 我叫張陵八毯,是天一觀的道長。 經(jīng)常有香客問我瞄桨,道長话速,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 55,259評(píng)論 1 279
  • 正文 為了忘掉前任芯侥,我火速辦了婚禮泊交,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘筹麸。我一直安慰自己活合,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,263評(píng)論 5 371
  • 文/花漫 我一把揭開白布物赶。 她就那樣靜靜地躺著白指,像睡著了一般。 火紅的嫁衣襯著肌膚如雪酵紫。 梳的紋絲不亂的頭發(fā)上告嘲,一...
    開封第一講書人閱讀 49,036評(píng)論 1 285
  • 那天,我揣著相機(jī)與錄音奖地,去河邊找鬼橄唬。 笑死,一個(gè)胖子當(dāng)著我的面吹牛参歹,可吹牛的內(nèi)容都是我干的仰楚。 我是一名探鬼主播,決...
    沈念sama閱讀 38,349評(píng)論 3 400
  • 文/蒼蘭香墨 我猛地睜開眼犬庇,長吁一口氣:“原來是場噩夢(mèng)啊……” “哼僧界!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起臭挽,我...
    開封第一講書人閱讀 36,979評(píng)論 0 259
  • 序言:老撾萬榮一對(duì)情侶失蹤捂襟,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后欢峰,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體葬荷,經(jīng)...
    沈念sama閱讀 43,469評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,938評(píng)論 2 323
  • 正文 我和宋清朗相戀三年纽帖,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了宠漩。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,059評(píng)論 1 333
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡懊直,死狀恐怖哄孤,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情吹截,我是刑警寧澤瘦陈,帶...
    沈念sama閱讀 33,703評(píng)論 4 323
  • 正文 年R本政府宣布凝危,位于F島的核電站,受9級(jí)特大地震影響晨逝,放射性物質(zhì)發(fā)生泄漏蛾默。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,257評(píng)論 3 307
  • 文/蒙蒙 一捉貌、第九天 我趴在偏房一處隱蔽的房頂上張望支鸡。 院中可真熱鬧,春花似錦趁窃、人聲如沸牧挣。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,262評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽瀑构。三九已至,卻和暖如春刨摩,著一層夾襖步出監(jiān)牢的瞬間寺晌,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,485評(píng)論 1 262
  • 我被黑心中介騙來泰國打工澡刹, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留呻征,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 45,501評(píng)論 2 354
  • 正文 我出身青樓罢浇,卻偏偏與公主長得像陆赋,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子嚷闭,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,792評(píng)論 2 345

推薦閱讀更多精彩內(nèi)容