2012-11-12 31 views
1

我實現了嵌套的UITableViews,這樣,從父數據列表中選擇一個特定的行時,從服務器獲取子節點數據並將它們重新加載到同一個UITableview中。我已經給出了使用字典返回到父節點的規定,並且一切正常。當我將父數據列表移動到子數據列表時,我想要導航樣式動畫。有人可以幫助我如何做到這一點。iOS:UITableView重載動畫

我一直在使用下面的代碼UIViewAnimationOptionTransitionFlipFromLeftUIViewAnimationOptionTransitionFlipFromRight動畫它翻轉角度嘗試 - 我在尋找類似的,但沒有翻轉 - 簡單的導航風格的動畫就像我要假裝我推另一個UITableView的。

[UIView transitionWithView: self.listTableView 
        duration: 0.35f 
        options: UIViewAnimationOptionTransitionFlipFromLeft 
        animations: ^(void) { 
         [self.listTableView reloadData]; 
        } completion: ^(BOOL isFinished){ 
        }]; 

回答

2

這裏是邏輯與代碼。

您需要導入QuartzCore framework in .h`使用下面一塊代碼。 AS#進口

// Method to replace a given subview with another using a specified transition type, direction, and duration 
-(void)replaceSubview:(UIView *)oldView withSubview:(UIView *)newView transition:(NSString *)transition direction:(NSString *)direction duration:(NSTimeInterval)duration 
    { 
    // Set up the animation 
    CATransition *animation = [CATransition animation]; 
    // Set the type and if appropriate direction of the transition, 
    if (transition == kCATransitionFade) 
     { 
     [animation setType:kCATransitionFade]; 
    } 
    else 
    { 
    [animation setType:transition]; 
    [animation setSubtype:direction]; 
} 
// Set the duration and timing function of the transtion -- duration is passed in as a parameter, use ease in/ease out as the timing function 
[animation setDuration:duration]; 
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 
[[oldView layer] addAnimation:animation forKey:@"transitionViewAnimation"];  
    } 

致電上述方法時的TableView行得到如下點擊。

 [self replaceSubview:thisTableView 
       withSubview:thisTableView 
        transition:kCATransitionPush 
        direction:kCATransitionFromLeft 
        duration:0.3]; 


//thisTableView is instance of UItableView. 
+0

謝謝!這看起來很有趣。什麼是kAnimationKey? – applefreak

+0

@AppleDeveloper對不起,我忘了傳遞它,它是'transitionViewAnimation'.and我要把它放在我的答案。 – Kamarshad

+0

工作太棒了。謝謝。關鍵必須是「transitionViewAnimation」嗎?我GOOGLE了,發現每個人都使用相同的字符串爲kAnimationKey :) – applefreak