你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iCarousel詳解

iCarousel詳解

編輯:IOS開發綜合

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)

支持的編譯目標-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

最早支持的開發目標-iOS 4.3 / Mac OS 10.7

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

最早兼容的開發目標-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.

注意:“支持”的意思是這個版本的庫已經被測試過了。“可兼容”的意思是在這個版本上這個庫是可以工作的(它並不依賴於任何不可獲得的sdk特性)但是已經不再對兼容性做測試,並且可能需要稍作改動或bug修復來正確運行。

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通過條件性編譯,可以自動工作在arc和非arc的工程中。沒有必要從arc確認程序中排除iCarousel文件,或者去使用arc轉換工具去轉換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內容或條目,但是總是確保一旦你的內容已經被加載了,在更新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類文件(示例文件和“資產”不需要)拖拽到你的工程中,並且添加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現在與變色龍iOS-to-Mac轉換庫兼容(https://github.com/BigZaphod/Chameleon)。在使用帶有變色龍的iCarousel時,在你工程的預處理程序宏定義中添加USING_CHAMELEON 。如何使用變色龍把你的iOS iCarousel app整體搬移到Mac OS請查看Chameleon示例工程。注意,tap-to-center目前是不工作的,並且,滾動必須使用2個手指滾動手勢才能完成,而不是點擊和拖動(這些都是由於Chameleon手勢識別器的實現上的特點/限制)。

Carousel Types

Carousel類型

iCarousel supportsthe following built-in display types:

Carousel支持以下內置的展示樣式:

iCarouselTypeLinear

線性的

iCarouselTypeRotary

可旋轉的

iCarouselTypeInvertedRotary

反向旋轉式

iCarouselTypeCylinder

圓柱式

iCarouselTypeInvertedCylinder

反向圓柱式

iCarouselTypeWheel

車輪式

iCarouselTypeInvertedWheel

反向車輪式

iCarouselTypeCoverFlow

封面流

iCarouselTypeCoverflow2

封面流樣式2

iCarouselTypeTimeMachine

時光機

iCarouselTypeInvertedTimeMachine

反向時光機

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

你也可以使用iCarouselTypeCustom和carousel:itemTransformForOffset:baseTransform:代理方法來實現自己的定制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樣式的不同之處很細微,然而,iCarouselTypeCoverFlow2的邏輯相當復雜。如果你輕彈carousel,他們基本上是一樣的,但是如果你使用手指慢慢拖動carousel,不同點就會明顯。iCarouselTypeCoverFlow2是為了模擬盡可能接近標准的蘋果封面流效果而設計的,並且可能在未來會為了這個目標而巧妙地變化。

Properties

屬性

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

iCarousel有以下屬性(注意:對於Mac OS,當使用屬性時用NSView替換UIView)

@property(nonatomic,weak)IBOutletid dataSource;

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

一個支持iCarouselDataSource協議且能提供視圖來填充carousel的對象。

@property(nonatomic,weak)IBOutletiddelegate;

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

一個支持iCarouselDelegate協議且可以響應iCarousel事件和布局請求的對象。

@property(nonatomic,assign)iCarouselType type;

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

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

@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;

用來稍稍調整在多種3dcarousel視圖中視覺按照透視法縮短效果的,它應該是一個負數,小於0且大於-0.01,這個范圍之外的值將會產生非常奇怪的結果。默認值是-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.

這個屬性用來調整carousel item views相對於carousel中心的邊距。它的默認值是CGSizeZero,意思是carousel items是居中的。改變這個屬性的值來移動carousel items而不必改變他們的視覺。消失點隨著carousel items移動,所以,如果你把carousel items移動到下邊,如果你在carousel上向下看時他就不會出現。

@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.

這個屬性用來調整相對於carousel items的用戶視點,它有一個副作用就是調整contentOffset。如果你向上移動視點,然後carousel顯示是向下移動。與contentOffset不同,移動視點也會改變和carousel items有關的視角消失點,所以如果你向上移動視點,他就會像你在carousel上向下看一樣出現。

@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).

這個率用於carousel被快速輕擊時carousel減速率。值越大表示減速越慢。默認值是0.95.值應該在0.0(設置為這個值時,carousel被釋放時立即停止滾動)和1.0(設置為這個值時,carousel繼續無限滾動而不減速,直到它到達底部)之間。

@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.

設置carousel在超出底部和返回時是否應該彈跳,或者是停止並掛掉。注意,在carousel樣式設置為纏繞樣式時或者carouselShouldWrap代理方法返回為yes時,這個屬性不起作用。

@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;

一個非包裹樣式的carousel在超過底部時將彈跳的最大距離。這個用itemWidth的倍數來衡量的,所以1.0這個值意味著彈跳一整個item的寬度,0.5這個值是一個item寬度的一半,以此類推。默認值是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.

使能或者禁止用戶滾動carousel。如果這個值被設為no,carousel仍然可以以編程方式被滾動。

@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。這個屬性是只讀的。如果你想重寫這個默認值,實現carousel:valueForOption:withDefault:方法且給iCarouselOptionWrap返回一個值。

@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的數量(只讀),要設置他的話,實現numberOfItemsInCarousel:這個數據源方法。注意,所有這些item views在一個給定的時間點將會被加載或者可見-carousel當它滾動的時候經要求加載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中展示的占位視圖的數量(只讀)。要設置他,實現一下numberOfPlaceholdersInCarousel:這個數據源方法。

@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.

同時顯示在屏幕上的carousel itemviews的最大數量(只讀)。這個屬性對執行最優化很重要,且是基於carousel的樣式和視圖的frame被自動計算的。如果你想重寫這個默認值,實現一下carousel:valueForOption:withDefault:(原文件中沒有找到這個方法????工程中使用的是- (NSUInteger)numberOfVisibleItemsInCarousel:(iCarousel *)carousel數據源方法)這個代理方法且給iCarouselOptionVisibleItems返回一個值。

@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.

一個包含了所有當前加載的和在carousel中可見的item views的索引,包括占位視圖的數組,這個數組包含NSNumber的對象,他們的整數值與視圖的索引匹配。這些item views的索引從0開始且與加載視圖時數據源傳遞的索引匹配,然而,任何占位視圖的索引將是負數或者大於等於numberOfItems。數組中的placeholder views的索引並不等於數據源中使用的占位視圖的索引。

@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).

一個存放當前carousel中展示的所有item views的數組(只讀),它包括任何可見的占位視圖。這個數組中視圖的索引並不與item的索引匹配,然而,這些視圖的順序與visibleItemIndexes數組屬性中的順序匹配,你可以通過從visibleItemIndexes數組中去掉??對應的對象來在這個數組中獲取一個指定視圖的索引(或者,你可以僅僅用indexOfItemView:方法,這個會更簡單)

@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散置這些視圖。如果你想讓一個視圖出現在所有carouselitems的前邊或者後邊,你應該直接添加它到iCarousel view本身來替代。注意,在contentView中視圖的順序是受當app執行時的頻率和未標注的變化決定的。任何添加到contentView中的視圖應該將他們的userInteractionEnabled屬性設置為no來防止和iCarousel的觸摸時間處理放生沖突。

@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的整數倍來計算的carousel當前的滾動偏移量,這個值,被截取為最接近的整數,是currentItemIndex值。當carousel運動中,你可以使用這個值定位其他屏幕的元素。這個值也可以被編程方式設置如果你想滾動carousel到一個特定的偏移。如果你想禁用內置手勢處理並提供自己的實現時,這個可能有用。

@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.

這是當用戶用手指拖動carousel時偏移量的乘數。它並不影響編程的滾動和減速的速度。對大多數carousel樣式這個默認值是1.0,但是對CoverFlow-style樣式的carousels默認值是2.0,來彌補他們的items在空間上更緊湊,所以必須拖拽更遠來移動相同的距離的事實。你不能直接設置這個值,但是可以通過實現carouselOffsetMultiplier:代理方法來重寫默認值。

這個應該是滑動一下移動的距離。

@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.

當前carousel中居中的item的索引,設置這個屬性相當於調用scrollToItemAtIndex:animated:方法時將animated參數設置為no。

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

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

當前carousel中居中的item view。這個視圖的索引與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的寬度(只讀)。這是自動從使用carousel:viewForItemAtIndex:reusingView:數據源方法第一個傳到carousel中的視圖中繼承來的。你也可以使用carouselItemWidth:代理方法重寫這個值,這個方法會改變分配給carousel items的空間(但是不會對這些item views重寫設置大小或規模)。

@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.

當設置為yes時,點擊任何在carousel中的item而不是那個匹配currentItemIndex的視圖,將會使平滑動畫移動到居中位置。點擊當前被選中的item將沒有效果。默認值是yes。

@property(nonatomic,assign)CGFloatscrollSpeed;

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

這是當用戶用手指輕擊carousel時滾動速度乘數。默認值是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.

這個屬性用於iCarouselTypeCoverFlow2的carousel變換。它是被暴露的以便於你可以使用carousel:itemTransformForOffset:baseTransform:代理方法實現自己的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.

默認情況下,carousel被輕擊時會停在一個准確的item邊界。如果你設置這個值為no,他會自然停止然後-如果scrollToItemBoundary被設置為yes-滾回或者向前滾動到最接近的邊界

@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.

默認情況下,不管carousel何時停止移動,他會自動滾動到最近的item邊界。如果你設置這個屬性為no,carousel停止後將不會滾動且不管在哪兒他都會停下來,即使他不是正好對准當前的索引。有一個特例,如果打包效果被禁止且bounces呗設置為yes,然後,不管這個設置是什麼,carousel會自動滾回第一個或者最後一個索引,如果它停下來時超出了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.

在默認情況下,在iOS中iCarousel會使用CADisplayLink而不是NSTimer來進行動畫。在Mac OS上,使用的卻是CVDisplayLinkAPI。這個在屏幕刷新時提供了更好的同步效果,但是當carousel與其他視圖或動畫結合,有時會妨礙動畫正常運行。如果你發現carousel被拖動後沒有持續移動,試一下把這個屬性置為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.

這個屬性切換,不管carousel是水平展示還是垂直展示的。所有內嵌的carousel樣式在這兩個方向上都可以運行。切換到垂直將會改變carousel的布局和屏幕上的切換方向。注意,自定義的carousel變換不受這個屬性影響,但是,切換手勢的方向還是會受影響。

@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將會忽略垂直於carousel方向的切換手勢。目前,一個水平的carousel,垂直切換將不會被攔截。這就意味著你可以獲得一個在carouselitem view裡的垂直滾動的scrollView切它依然會正確工作。默認值為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.

這個實際上不是iCarousel的屬性,但是是從UIView繼承來的。它被包含在這裡是因為他是一個經常被漏掉的特性。設置為yes來防止carousel item views超出他們的界限。你可以在InterfaceBuilder裡通過點擊'Clip Subviews'選項來設置這個屬性。默認值是no。

Methods

方法

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

iCarousel類有以下方法(注意:對於Mac OS,在方法的參數中用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.

這個方法會使carousel居中在一個特定的item,立即或者使用一個平滑的動畫。對於打包的carousels,carousel將會自動決定滾動的最短(直線會或者包著的)距離。如果你需要控制這個滾動的方向,或者想滾動多於一個分辨率,使用scrollByNumberOfItems這個方法。

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

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

這個方法允許你來控制carousel使用多長時間來滾動到特定的索引。

-(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.

這個方法允許你使用一個固定的距離滾動carousel,以carousel的item寬度來衡量。整數或負數可能由itemCount來具體確定,取決於你希望滾動的方向。iCarousel很好的處理了邊界問題,所以如果你指定了一個大於carousel中items數量的值,滾動或者在到達carousel底部時被夾緊(如果打包被禁止),或者無停頓地包裹。

-(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.

這個方法工作起來和scrollToItemAtIndex:方法一樣,但是允許你移動到一個微小的偏移。如果你想達到一個非常准確的動畫效果時這個可能有用。注意,如果scrollToItemBoundary屬性被設置為yes,當你調用這個方法之後carousel會自動滾動到最近的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.

這個方法作用與scrollByNumberOfItems:方法一樣,但是允許你滾動到一個微小數量的items。如果你想達到一個非常准確的動畫效果時可能有用。注意,如果scrollToItemBoundary屬性被設置為yes,在你調用這個方法後carousel無論如何會自動滾動到最近一個item索引。

(這個應該是滾動幾個items)

-(void)reloadData;

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

這個方法重新從數據源加載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視圖。注意,這個索引和carousel的位置有關,且不是在visibleItemViews數組中的位置,這可能是不一樣的。傳遞一個賦值或者一個大於等於numberOfItems的整數來取回占位視圖。這個方法只有在是可見視圖且情況下才工作,且如果這個在指定索引處的視圖還沒被加載時,或者這個索引超出范圍時,將返回空。

-(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.

這個是carousel中指定item view的索引。對item views和placeholder views起作用,但是,placeholder view索引並不和數據源中的索引匹配,且有可能是負值。(查看上面indexesForVisibleItems屬性介紹的細節)。這個方法只對可見的item views起作用且對目前沒有加載的視圖會返回NSNotFound。對於一列所有加載的視圖,使用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.

這個方法給你或者是傳遞的視圖或者是包含有作為參數的視圖的視圖的item索引。它通過以傳遞進來的視圖為開始,向上遍歷視圖層級,直到找到一個itemview並返回他在carousel中的索引。如果沒有找到當前加載的item view,它會返回NSNotFound。這個方法對處理一個item view內嵌的事件控制極其有用。它允許你綁定你的在控制器中控制單一行為方法的item,且會找出控制觸發相關行為的item。你可以看一下在Controls Demoexample工程中這個技術的例子。

看到這兒了!

-(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整數倍來記的指定的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

協議

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中界面的數量

-(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.

返回一個在carousel中要在指定索引處顯示的視圖,reusingView參數的作用就像UIPickerView,之前在carousel中展示過的界面被傳遞到方法中來循環使用。如果這個參數不是空,你可以設置它的屬性並返回它而不是創建一個新的視圖實例,這樣可以稍改善性能。與UITableView不同,這裡沒有重用id來區分不同的carousel界面類型。

所以如果你的carousel包含多個不同的視圖類型,那麼每次這個方法被調用的時候,你應該只是忽略這個參數並返回一個新的視圖。你應該確認carousel:viewForItemAtIndex:reusingView:方法每次被調用時,它要麼返回重用的視圖,要麼返回一個新的視圖實例而不是保留你自己的循環視圖池,因為為不同的carousel界面索引返回多個相同視圖的復制品可能造成顯示問題。

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中展示的占位視圖。占位視圖用來當carousel中界面太少而不能填滿carousel的寬度,並且你希望在空白的地方顯示一些東西時使用。它們隨著carousel移動並且像其他carousel界面一樣運行,但是它們不占numberOfItems數量,且不能被設置為當前選中的界面。當打包屬性被使能時占位視圖被隱藏。占位視圖或者顯示在carousel界面的任何一方。對於n個占位視圖,前n/2個界面將會出現在界面視圖的左邊,下一個n/2個界面會出現在右邊。你可以有奇數個占位視圖,這種情況下carousel會是不對稱的。

-(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.

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

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved