这样的事情?
-(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);
}];
}
谢谢你的回答塞巴斯蒂安!我证明你的代码正在工作! 但我无法同时执行我的A和B UIview。我将编辑我的问题并放置我的代码。如果你想要的话,你会看到计数器没有被同时执行。 –
不幸的是你的代码没有在我的电脑上运行。但是,我想如果你可以把你的代码放在这样一个动画语句中:'[UIView animateWithDuration:0.5 动画:^ v1.frame = CGRectMake(10,240,40,40); v2.frame = CGRectMake(140,10,40,40); }];'。你怎么看 ? – Sebastian
我做到了! ...我把计数器A和B放在相同的动画代码中,但它没有工作。 可能是因为A和B有它自己的动画......我介意A和B是着名的Apple FlipCounters这里是GIT原创项目的链接[link](https://github.com/reklis/flipcounter) I在UIView中使用该项目的FlipConuterView.h和FlipConuterView.m的两个实例。 –