5

ボタンが押されたときに画面の中央に画像 (PNG) を表示し、数秒後にフェードアウトさせようとしています。どうすればこれを行うことができますか?また、それは小さなpngなので、画面全体に合わせて拡大するのではなく、元のサイズで表示するにはどうすればよいですか? ヒント、提案、または回答は大歓迎です!

また、私はこのサイトを初めて使用するので、この質問が完全ではないと考える人もいるので、ヒントを教えてください。または、この質問を改善するのを手伝ってください。皆さん、寛大な回答をありがとうございます!:)

4

3 に答える 3

10

を次のように初期化UIImageViewしますUIImage

// Assuming MyImage.png is part of the project's resources.
UIImage *image = [UIImage imageNamed:@"MyImage.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
// Add imageView to a parent view here.
[UIView animateWithDuration:0.2f delay:3.0f options:0 
                 animations:^{imageView.alpha = 0.0;} 
                 completion:^{[imageView removeFromSuperview];}];
于 2012-09-12T11:38:36.650 に答える
3
 NSArray *animationArray = [NSArray arrayWithObjects:[UIImage imageNamed:@"myImage.png"], nil]; 

    [NSTimer scheduledTimerWithTimeInterval:.75 target:self selector:@selector(crossfade) userInfo:nil repeats:YES];

    mainImageView.animationImages = animationArray;                
    mainImageView.animationDuration = 4.5; //mainImageView is instance of UIImageView
    mainImageView.animationRepeatCount = 0;
    [mainImageView startAnimating];

    CABasicAnimation *crossFade = [CABasicAnimation animationWithKeyPath:@"contents"];
    crossFade.autoreverses = YES;
    crossFade.repeatCount = 1;
    crossFade.duration = 1.0;

およびターゲットメソッド:

- (void) crossfade {
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; // user dependent transition acn be set here
    mainImageView.alpha = !mainImageView.alpha;
    [UIView commitAnimations];
}
于 2012-09-12T11:39:25.813 に答える
3

ボタンを押して数秒間画像を表示するコードは次のとおりです。ボタンアクションに次のコードを追加します。

imageView.image=yourImage;
 [self performSelector:@selector(waitAndGo) withObject:nil afterDelay:5];

以下は、waitAndGo の実装です。

-(void)waitAndGo
{
    imageView.hidden=YES;
}
于 2012-09-12T11:40:56.103 に答える