2011-07-26 43 views
2

我無法從角落展開UITable。UITableView出現一個動畫(從一個角落展開)

這是我做的:

tableAccounts = [[UITableView alloc] initWithFrame:CGRectMake(0, 71, 0,0)]; 
     [self.view addSubview:tableAccounts]; 


     [UIView beginAnimations:@"tableAppearing" context:nil]; 
     [UIView setAnimationDuration:3.0f]; 
     [UIView setAnimationCurve:UIViewAnimationCurveLinear]; 

     tableAccounts.frame = CGRectMake(0, 71, 320, 332); 
     tableAccounts.backgroundColor = [UIColor redColor]; 

     [UIView commitAnimations]; 

我可以看到該表從左上角出現,而不是擴大!我的意思是表格從不改變它的大小,它的大小始終是相同的,並且它正在出現。 我想要同樣的效果,但從一張小桌子開始,並且做得更大。

有可能嗎?

回答

2

您應該可以通過對tableview應用一個縮放轉換並從角落移動它。以下應該從右下角開始增長。

CGRect frame = self.view.frame; 
int width = CGRectGetWidth(frame); 
int height = CGRectGetHeight(frame); 

// Make the frame the size you want in the end and place it centered on the corner. 
CGRect startTvFrame = CGRectMake(width/2, height/2, width, height); 
UITableView *tableView = [[UITableView alloc]initWithFrame:startTvFrame]; 

// Scale the view so that it starts out small 
CGAffineTransform t = CGAffineTransformMakeScale(.001, .001); 
tableView.transform = t; 

[self.view addSubview:tableView]; 

// Animations 
[UIView animateWithDuration:3.0f 
         delay:0.0f 
        options:UIViewAnimationCurveLinear 
       animations:^{ 
        // Reset the scale 
        tableView.transform = CGAffineTransformMakeScale(1, 1); 

        // Position the tableview 
        CGRect tvFrame = tableView.frame; 
        tvFrame.origin.x = 0; 
        tvFrame.origin.y = 0; 
        tableView.frame = tvFrame; 
       } 
       completion:nil]; 

[tableView release];