如何在'UIView'中給'圖片'動畫
multiple images
在Different Locations
?如何在UIView的不同位置將圖像動畫提供給多個圖像?
1)我有3張圖片。
2),我想在3 different locations
起勁添加這些3 Images
,是指通過一個圖像animatedly
與some duration
添加一個??
我該如何做到這一點?
如何在'UIView'中給'圖片'動畫
multiple images
在Different Locations
?如何在UIView的不同位置將圖像動畫提供給多個圖像?
1)我有3張圖片。
2),我想在3 different locations
起勁添加這些3 Images
,是指通過一個圖像animatedly
與some duration
添加一個??
我該如何做到這一點?
根據您的要求,你想一個
的第一圖像動畫爲此完工塊動畫圖像一個動畫第二圖像等類似下面的代碼
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"-t%d",1]]];
[imgView setBackgroundColor:[UIColor redColor]];
UIImageView *imgView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"-t%d",2]]];
[imgView2 setBackgroundColor:[UIColor redColor]];
UIImageView *imgView3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"-t%d",2]]];
[imgView3 setBackgroundColor:[UIColor redColor]];
[self.view addSubview:imgView];
[self.view addSubview:imgView2];
[self.view addSubview:imgView3];
[UIView animateWithDuration:0.5 delay:1.0 options:UIViewAnimationOptionLayoutSubviews animations:^{
[imgView setFrame:CGRectMake(0, 0, 150, 150)];
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.5 delay:1.0 options:UIViewAnimationOptionLayoutSubviews animations:^{
[imgView2 setFrame:CGRectMake(self.view.frame.size.width - 150, 0, 150, 150)];
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.5 delay:1.0 options:UIViewAnimationOptionLayoutSubviews animations:^{
[imgView3 setFrame:CGRectMake(0, self.view.frame.size.height - 150, 150, 150)];
} completion:^(BOOL finished) {
}];
}];
}];
它會幫助你:)
@PKT ....你的代碼對我來說工作正常 –
比方說3次是_redView
,_greenView
和_blueView
退房下面的方法來移動這些從一個到另一個位置。如果需要,我可以使用隨機位置。 Here you can have working example of it只需選擇ViewAnimationsTest
項目的工作空間並運行。
- (int) randomFloatingGenerator : (int) max{
return arc4random() % max;
}
- (void) animate3Views {
[UIView animateWithDuration:2.0
animations:^{
_redView.transform = CGAffineTransformMakeTranslation([self randomFloatingGenerator : 270], [self randomFloatingGenerator:480]);
_greenView.transform = CGAffineTransformMakeTranslation([self randomFloatingGenerator : 270], [self randomFloatingGenerator:480]);
_blueView.transform = CGAffineTransformMakeTranslation([self randomFloatingGenerator : 270], [self randomFloatingGenerator:480]);
} completion:^(BOOL finished) {
[self animate3Views];//if don;t want continuous translation remove this line
}];
}
在這裏你可以有它的工作示例,https://github.com/rptwsthi/DevelopmentSupportWorkspace只需選擇ViewAnimationsTest項目工作空間和運行。 – rptwsthi
@rptwsthi ...在那個例子中,你能告訴我哪一個我必須使用 –
可能最簡單的方法是使用3個延遲調用的動畫。
for (NSInteger i = 0; i < 3; i++) {
UIView *view = myViews[i];
CGRect frame = [self frameForViewAtIndex: i];
NSTimeInterval duration = 0.5;
NSTimeInterval delay = i * 0.5;
[UIView animateWithDuration: duration delay: delay options: 0 animations: ^{
view.frame = frame;
} completion: nil];
}
凡myViews是視圖陣列進行動畫,frameForViewAtIndex:是,對對應的視圖返回幀的方法。
@roselovely在這段代碼中不清楚嗎? –
....你能告訴如何在那裏添加圖片 –
你需要uiimageview動畫快速緩慢的關島區域? – Shreyank
UIView animateWithDuration? –
@Shreyank ....不快慢......但我們想在3個不同的位置持續一段時間後逐個添加3張圖片......在一個地方放置一張圖片,放置該圖片後,下一張圖片生成並進入進入下一個地方 –