2013-01-22 17 views

回答

7

在我的情況,我被我的viewDidLoad中使用的方法[self.vwCoverFlow scrollToItemAtIndex:2 animated:YES];的幫助。

+0

謝謝..做工精細。 – Sudhakar

+0

你救我一天的男人:)謝謝! – Irfan

+0

但是,此滾動輪播在第二個索引不顯示從最左邊的第一個項目? –

4

如果您想要線性滾動,您可以使用swipeView類,它來自與iCarousel相同的開發人員,但僅用於線性滾動。我已經使用它,它支持左對齊。 它很容易添加和使用,一樣iCarousel

這裏是鏈接在你的情況下,代碼https://github.com/nicklockwood/SwipeView

0

,我想用2佔位符建議。例如:你有n張照片,那麼你將有(n-2)項和2個佔位符。 - 項目索引從1到(n-2)。 - 佔位符的索引是0和(n-1)。 現在我們將有一些像這樣的代碼:

#pragma mark iCarousel DataSource 

- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel 
{ 
    //if we have n photos, then number of items is (n-2) 
    int count = _movieGalleries.count; 
    return count >= 3 ? count - 2 : count; 
} 

- (NSUInteger)numberOfPlaceholdersInCarousel:(iCarousel *)carousel 
{ 
    //2 placeholder 
    return _movieGalleries.count >= 3 ? 2 : 0; 
} 

#pragma mark iCarousel Delegate 
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view 
{ 
    //reuse your view 
    UIView *yourview = ... 

    //get your data 
    //index of item is 1 -> n-2, index of placeholder is 0 and n-1 
    Item *item = [_listItems objectAtIndex:index + 1]; 

    //config your view 
    ... 
    return yourView; 
} 

- (UIView*)carousel:(iCarousel *)carousel placeholderViewAtIndex:(NSUInteger)index reusingView:(UIView *)view 
{ 
    //index of placeholder is 0 and n-1 
    //Trick: we use viewForItemAtIndex for getting placeholder view 
    index = index == 0 ? - 1 : carousel.numberOfItems; 
    return [self carousel:carousel viewForItemAtIndex:index reusingView:view]; 
} 

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

    //in carousel with placeholder, index of selected item is -1, 0, 1, ..., (n-2). which -1 and (n-2) is index of placeholders. So that we need to increase index by 1 
    NSLog("current index: %i", index + 1); 
} 
1

Wrap屬性設置爲YES,並返回placeholderinCarousel的數量爲2

1

我有同樣的問題,並與下面的技巧做;)

問題: 我需要查看只顯示3個始終左對齊的項目。

決議: 我所做的是總是至少3項。如果我有0,1或2項,我總是創建3,但那些不需要顯示我創建爲空的UIView。我總是有2個佔位符,但在某些情況下,其中一個或兩個都是空的。

例如 如果我們有2個項目要顯示,我實際上創建了三個,但第三個是空的UIView。我創建了兩個佔位符和一個Item。

  • 第一項是第一佔位符索引0
  • 第二項是項目
  • 第三項是第二佔位但空的UIView

如果我們有1項顯示,再次創建三個,但第二個和第三個是空的UIView。和前面的例子一樣,我創建了兩個佔位符和一個Item。

  • 第一項是第一佔位符在索引0處
  • 第二項是項目但用空的UIView
  • 第三項是第二佔位符但用空的UIView

由於這個邏輯我總是清理視圖時重用([v removeFromSuperview]),以確保它是乾淨的,如果需要顯示新的我添加它([查看addSubview ...))。對於項目佔位符相同的邏輯

如果您需要有3個以上顯示的項目,你可以用同樣的邏輯,但變化值3到別的東西。如果我錯了,我更新;)

這裏是我的代碼爲我工作的一部分;)

- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel 
{ 
    return [[self getRecordings] count] > 3? [[self getRecordings] count] - 2: 1; 
} 

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view 
{ 
    if (view == nil) 
    { 
     view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 30)]; 
    } 
    else 
    { 
     // If reusing remove content from holder view for fake items 
     for (UIView *v in view.subviews) 
     { 
      [v removeFromSuperview]; 
     } 
    } 

    if ([[self getRecordings] count] >= 2) 
    { 
     [view addSubview:[(RecordingItemViewController*)[_recordingItemViewControllers objectAtIndex:index + 1] view]]; 
    } 

    return view; 
} 

- (NSUInteger)numberOfPlaceholdersInCarousel:(iCarousel *)carousel 
{ 
    return 2; 
} 

- (UIView *)carousel:(iCarousel *)carousel placeholderViewAtIndex:(NSUInteger)index reusingView:(UIView *)view 
{ 
    if (view == nil) 
    { 
     view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 30)]; 
    } 
    else 
    { 
    // If reusing remove content from holder view for fake items 
     for (UIView *v in view.subviews) 
     { 
      [v removeFromSuperview]; 
     } 
    } 

    if (([[self getRecordings] count] > 0 && [[self getRecordings] count] < 3 && index == 0) || [[self getRecordings]count] >= 3) 
    { 
     [view addSubview:[(RecordingItemViewController*)(index == 0? [_recordingItemViewControllers objectAtIndex:0]: [_recordingItemViewControllers lastObject]) view]]; 
    } 

    return view; 
} 
1

這對我的作品

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

     [carousel scrollToItemAtIndex:photosArray.count/2 animated:YES]; 

     return [photosArray count]; 
     }