2010-10-01 44 views

回答

2

我建議張貼問題之前,閱讀文檔。完全不熟悉這個庫,在30秒內,我下載了源代碼,找到了這些文檔,直到找到 - (void)flowCover:(FlowCoverView *)視圖didSelect:(int)cover,這看起來像一個委託方法。

乍一看,你看起來並不是想知道什麼是正面和中心,只是用戶選擇了什麼(這可能意味着「什麼剛剛變成了前鋒和中鋒」)。測試一下,看看。

+0

,只有當用戶選擇圖像觸發方法。這不是我所需要的 – Lilz 2010-10-01 13:38:46

+0

然後,您可能需要深入研究源代碼並將其擴展爲報告最前面的項目,因爲文檔沒有提及任何此類通知。 – 2010-10-01 13:41:02

1

您可以輕鬆地改變委託協議中FlowCoverView.h這樣得到這個通知:

@protocol FlowCoverViewDelegate 
- (int)flowCoverNumberImages:(FlowCoverView *)view; 
- (UIImage *)flowCover:(FlowCoverView *)view cover:(int)cover; 
- (void)flowCover:(FlowCoverView *)view didSelect:(int)cover; 
- (void)flowCover:(FlowCoverView *)view highlighted:(int)cover; //<-- Added 
@end 

而與此更換您-[FlowCoverView driveAnimation]方法FlowCoverView.m:

- (void)driveAnimation 
{ 
    double elapsed = CACurrentMediaTime() - startTime; 
    if (elapsed >= runDelta) [self endAnimation]; 
    else [self updateAnimationAtTime:elapsed]; 

    /* 
    * Change by Uppfinnarn <[email protected]>. 
    * This will give the Delegate a message every time the highlighted cover (eg. the one in the center) changes. 
    * Can be used to display subtitles for example. 
    */ 

    if (delegate) [delegate flowCover:self highlighted:(int)floor(offset + 0.01)]; // make sure .99 is 1 

}

在某處創建一個UILabel並將其放置在FlowCoverView的頂部(確保它的不透明是NO,以便它不在其後面創建黑盒子),然後監視或-[flowCover:highlighted:]瞭解哪個封面當前位於中心並相應地更改文字。

請注意,只有在動畫移動後,這不會告知您何時首次創建視圖。你必須自己弄清楚第一個標題。

另外,當用戶用手指拖動時,只有當它「自由滑動」時,這不會給你通知。

編輯: 這個替換您的-[FlowCoverView touchesMoved:withEvent:]方法來獲取回調當用戶用手指拖過:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    CGRect r = self.bounds; 
    UITouch *t = [touches anyObject]; 
    CGPoint where = [t locationInView:self]; 
    double pos = (where.x/r.size.width) * 10 - 5; 

    if (touchFlag) { 
      // determine if the user is dragging or not 
      int dx = fabs(where.x - startTouch.x); 
      int dy = fabs(where.y - startTouch.y); 
      if ((dx < 3) && (dy < 3)) return; 
      touchFlag = NO; 
    } 

    int max = [self numTiles]-1; 

    offset = startOff + (startPos - pos); 
    if (offset > max) offset = max; 
    if (offset < 0) offset = 0; 
    /* 
    * Change by Uppfinnarn <[email protected]>. 
    * Based on Ilkka Pirttimaa <[email protected]>'s solution for notifications. 
    * when the animation stops. 
    * 
    * This will give the Delegate a message every time the highlighted cover (eg. the one in the center) changes. 
    * Can be used to display subtitles for example. 
    */ 
    if(delegate) [delegate flowCover:self highlighted:(int)floor(offset + 0.01)]; 
    [self draw]; 

    double time = CACurrentMediaTime(); 
    if (time - startTime > 0.2) { 
     startTime = time; 
     lastPos = pos; 
    } 
} 
相關問題