這樣的事情?
-(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的兩個實例。 –