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 回答