[英]In a UIView how can I chain a lot of animations to each other and have them run consecutively
[英]How to call two animations without them interfering with each other?
我制作了一個帶有動畫的提示框,但我也想在用戶點擊蠟燭按鈕時獲得 -10 個硬幣,所以我創建了一系列照片,這些照片制作了向用戶描繪 -10 的動畫。 .
問題是每次按下蠟燭按鈕時 -10coins 動畫都會覆蓋提示滑動框並替換它,從而使用戶無法再次找到提示......
代碼:
- (IBAction)firstHintq:(id)sender {
[_hintView setHidden:NO];
[_hintViewTwo setHidden:YES];
[_hintViewThree setHidden:YES];
_hintView.text = @"Ηταν η τεταρτη τηλεφωνικη εταιρια στην Ελλαδα";
//connected to global BOOL
if (!btn1Pressed) {
if((coins -10) >= 0){
coins = coins -10;
score = score -2;
// Load images starts
NSArray *imageNames = @[ @"coin-10-1.png", @"coin-10-2.png",
@"coin-10-3.png", @"coin-10-4.png", @"coin-10-5.png", @"coin-10-6.png",
@"coin-10-7.png", @"coin-10-8.png", @"coin-10-9.png", @"coin-10-10.png", @"coin-10-11.png",@"coin-10-12.png", @"coin-10-13.png",@"coin-10-14.png",@"coin-10-15.png"];
NSMutableArray *images = [[NSMutableArray alloc] init];
for (int i = 0; i < imageNames.count; i++) {
[images addObject:[UIImage imageNamed:[imageNames objectAtIndex:i]]];
}
// Normal Animation
UIImageView *animationImageView = [[UIImageView alloc] initWithFrame:CGRectMake(80, 200, 30, 70)];
animationImageView.animationImages = images;
animationImageView.animationDuration = 1.5;
animationImageView.animationRepeatCount = 10;
[self.view addSubview:animationImageView];
[animationImageView startAnimating];
//coin animation ends
//changes image
[_candleone setImage:[UIImage imageNamed:@"candle2_03.png"] forState:UIControlStateNormal];
self.candletwo.hidden = NO;
//Animates the 2nd candle
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
CGPoint center = [_candletwo center];
center.x = 88;
center.y = 70;
[_candletwo setCenter:center];
[UIView commitAnimations];
//sets the global BOOL as true
coinsLabel.text = [NSString stringWithFormat:@"%d",coins];
btn1Pressed = true;
}
else{
[_hintView setHidden:YES];
//Show an alert that the user has not enough coins
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"TITLE" message:@"MESSAGE" delegate:nil cancelButtonTitle:@"RETURN BUTTON" otherButtonTitles:nil];
[alert show];
}
}
}
如何解決此問題,以便兩個動畫都正確激活?
對於動畫更好地使用:
[UIView animateWithDuration:time // time is a double
delay:0.0f
options:UIViewAnimationOptionCurveEaseIn
animations:^() {
}
completion:^(BOOL finished) {
}];
然后你可以使用 2 animateWithDuration: delay: options: completion:
而OFC,可以嵌套2個:
[UIView animateWithDuration:time // time is a double
delay:0.0f
options:UIViewAnimationOptionCurveEaseIn
animations:^() {
}
completion:^(BOOL finished) {
[UIView animateWithDuration:time // time is a double
delay:0.0f
options:UIViewAnimationOptionCurveEaseIn
animations:^() {
}
completion:^(BOOL finished) {
}];
}];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.