2012-09-30 25 views
1

我在網上衝浪,但我無法解決我遇到的問題。 我正在開發一個iPhone應用程序。 這裏的問題:我有樹UIView A,B和C. A和B進入C. 當C有結果顯示時,我想同時執行A和B. A和B是一個反制動畫,每一個需要5秒。完成。但是我找不到同時顯示A和B的反向動畫的方法。 A動畫完成時始終執行B. 我試過塊(dispatch_queue_t),但我有相同的結果。 可以做我想做的事情嗎?同時執行兩個UIView(不是按順序)

被修改: code中的問題是計數器(A和B)不能同時執行。

回答

0

這樣的事情?

-(void)viewDidLoad { 
    [super viewDidLoad]; 
    [self startAnimation]; 
} 

-(void)startAnimation { 

    //Creating views 
    UIView *v1 = [UIView.alloc initWithFrame:CGRectMake(10, 10, 40, 40)]; 
    v1.backgroundColor = [UIColor blueColor]; 
    [self.view addSubview:v1]; 

    UIView *v2 = [UIView.alloc initWithFrame:CGRectMake(140, 240, 40, 40)]; 
    v2.backgroundColor = [UIColor redColor]; 
    [self.view addSubview:v2]; 

    //Animating views 
    [UIView animateWithDuration:0.5 
       animations:^{ 
        v1.frame = CGRectMake(10, 240, 40, 40); 
       }]; 


    [UIView animateWithDuration:0.5 
       animations:^{ 
        v2.frame = CGRectMake(140, 10, 40, 40); 
       }]; 
} 
+0

謝謝你的回答塞巴斯蒂安!我證明你的代碼正在工作! 但我無法同時執行我的A和B UIview。我將編輯我的問題並放置我的代碼。如果你想要的話,你會看到計數器沒有被同時執行。 –

+0

不幸的是你的代碼沒有在我的電腦上運行。但是,我想如果你可以把你的代碼放在這樣一個動畫語句中:'[UIView animateWithDuration:0.5 動畫:^ v1.frame = CGRectMake(10,240,40,40); v2.frame = CGRectMake(140,10,40,40); }];'。你怎麼看 ? – Sebastian

+0

我做到了! ...我把計數器A和B放在相同的動畫代碼中,但它沒有工作。 可能是因爲A和B有它自己的動畫......我介意A和B是着名的Apple FlipCounters這裏是GIT原創項目的鏈接[link](https://github.com/reklis/flipcounter) I在UIView中使用該項目的FlipConuterView.h和FlipConuterView.m的兩個實例。 –