2012-01-03 75 views
0

我有一個模仿照片應用程序的應用程序,它顯示一張縮略圖表,表示用戶點擊過的相冊。旋轉發生時,我無法模仿此窗口的動畫。供您參考我在談論的窗口如下:如何在縮略圖視圖中模仿照片應用程序的旋轉

enter image description here enter image description here

我能夠得到最終結果轉了罰款(即動畫完成後,一切正常),然而,我的輪換看起來不如照片應用程序。照片應用程序實際上看起來像是在旋轉窗口,您幾乎不會注意到照片可以重置自己。在我的,你可以看到縮略圖移動,看起來不太好。

有沒有人有線索的照片應用程序在做什麼?是否有可能加快動畫速度,或者可能使它在中間變得模糊不清,因此你無法看到發生了什麼?我的代碼如下:

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) 
    { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 
    else 
    { 
     for (UIButton *photoButton in [cell subviews]) 
     { 
      [photoButton removeFromSuperview]; 
     } 
    } 

    NSInteger photosPerRow; 

    if (self.interfaceOrientation == UIInterfaceOrientationPortrait) 
    { 
     photosPerRow = 4; 
    } 
    else 
    { 
     photosPerRow = 6; 
    } 

    CGRect frame = CGRectMake(4, 2, 75, 75); 

    for (int i = [indexPath row] * photosPerRow; i < (([indexPath row] * photosPerRow) + photosPerRow) && i < [[self photos] count]; i++) 
    { 
     [[photos objectAtIndex:i] setFrame:frame]; 
     [cell addSubview: [photos objectAtIndex:i]]; 
     frame.origin.x = frame.origin.x + frame.size.width + 4; 
    } 

    return cell; 
} 

那麼這裏就是我如何動畫在我的tableview控制器:

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
{ 
    [self.tableView reloadData]; 
    return (toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
} 

更新:嗯,我已經試過了很多。到目前爲止,我的所有代碼都切換到了滾動視圖,然後在發生旋轉時嘗試使縮略圖呈現如下動畫效果:淡出縮略圖,將其移至新位置,然後淡入。當然,我只用UIThumbViews需要移動的東西。我得出的結論是,蘋果必須使用兩種觀點才能將它們取消。一個視圖與舊的一組縮略圖視圖,然後旋轉新的一組縮略圖視圖。有任何想法嗎?

+2

我可以保證你的照片應用程序將不會被使用'UITableView'。我會用'UIScrollView'來做這件事,然後當你旋轉的時候,你移動個別圖像的框架,然後它應該看起來很平滑。 – mattjgalloway 2012-01-03 20:09:43

+0

我同意mattjgalloway。如果我是你,我會繼承UIScrollView的子類,並創建一個方法將一行的numberOfThumbnailPerRow和索引作爲輸入,並返回一個帶CGPoints的NSValue數組作爲每個方塊的原點(縮略圖)。 – Canopus 2012-01-04 14:18:59

+0

你絕對不使用UIScrollView,你使用UITableView,所以它只會加載出現在屏幕上的縮略圖,並將已經使用過的單元出列。當蘋果爲你做這件事時,沒有意義實現所有這些功能。噢,旋轉可以用兩行完成,如果你用tableview實現它而不是scrollview。 – 2012-02-08 00:29:31

回答

0

更新:這需要兩行代碼,你必須實現縮略圖視圖中tableview,而不是一個scrollView

[self.tableView reloadRowsAtIndexPaths: [self.tableView indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationFade]; 
[self.tableView reloadData];