2012-09-30 95 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的两个实例。 –