1

こんにちは、アニメーションは初めてで、最近遊んでみました。小さなリングから大きなリングに移動し、消えてから、別の場所を除いてプロセスを最初からやり直す円(リング)を表示したい。

これを行うために、同じリングの 6 つの異なるサイズの画像を作成しました。次のコードは私が行った方法ですが、プロセスを繰り返す方法がわかりません(つまり、メソッドを実行しますが、リングの場所は同じままです。乱数ジェネレーターをループする必要がありますが、いつ行うべきかわかりません画像が停止しているかどうかを確認します)。これが正しい方法でない場合は、お知らせください。PSリングは、最大の段階に達するまでに非常に醜く見えますが、理由はわかりません.

ありがとう

-(void) doWork
{

NSInteger number;
NSInteger number2;
NSLog (@"here");

number = (arc4random()%100)+1; 
number2 = (arc4random()%100)+1; 
 NSLog (@" hello numer1: %d", number);
 NSLog (@" hello numer2: %d", number2);

imageView = [[UIImageView alloc] initWithFrame:CGRectMake(number, number2, 135, 135)]; 

imageView.animationImages= [NSArray arrayWithObjects:
                            [UIImage imageNamed:@"smallestRing.png"],
                            [UIImage imageNamed:@"smallRing.png"], 
                            [UIImage imageNamed:@"mediumRing.png"],
                            [UIImage imageNamed:@"large2Ring.png"],
                            [UIImage imageNamed:@"largeRing.png"], nil]; 

imageView.animationDuration= 2.5;
imageView.animationRepeatCount= 0;
imageView.contentMode = UIViewContentModeScaleAspectFit;

[imageView startAnimating];
[self.view addSubview:imageView];

/*[NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(doWork) userInfo:nil repeats:YES];*/

}
4

2 に答える 2

1

UIImageViewのアニメーションが終了したかどうかを判断するために、boolisAnimatingをクエリできます。

PS:おそらくそれは醜いように見えます

imageView.contentMode = UIViewContentModeScaleAspectFit;

次のようなものを試してください

imageView.contentMode = UIViewContentModeCenter;
于 2012-06-07T23:28:23.177 に答える
1

サイズ変更 (または回転やトランジションなどの他の変換) が必要な唯一のアニメーションである場合は、メソッド +animateWithDuration を使用できます (ここで説明を見つけることができます)

次のようになります。

-(void) doWork
{

NSInteger number;
NSInteger number2;
NSLog (@"here");

number = (arc4random()%100)+1; 
number2 = (arc4random()%100)+1; 
 NSLog (@" hello numer1: %d", number);
 NSLog (@" hello numer2: %d", number2);

imageView = [[UIImageView alloc] initWithFrame:CGRectMake(number, number2, 135, 135)]; 

imageView.image = [UIImage imageNamed:@"largeRing.png"];
[self.view addSubview:imageView];

[self animate:imageView enlarge:YES];
}

-(void) animate:(UIImageView*)imageView enlarge:(BOOL)flag
{
if (flag) 
{
// then animating is starting
// and imageView will appear in random point of view
    int randomX = arc4random()%self.view.frame.size.width;
    int randomY = arc4random()%self.view.frame.size.height;
    imageView.center = CGPointMake(randomX, randomY);
}

double scale = flag ? 2 : 0.5;
[UIView animateWithDuration:5
         animations:^{ imageView.transform = CGAffineTransformMakeScale(scale,scale); }
         completion:^(BOOL finished){ [self animate:imageView: enlarge:!flag]; }];
}
于 2012-06-07T23:12:05.907 に答える