iPhone:UIImageView淡入 - 如何?

时间:2011-04-12 08:28:23

标签: iphone ios ipad uiimageview xamarin.ios

我有一个UIImageView我希望淡入。

有没有办法在基础UIViewController上启用它?

我已经翻译了最简单的答案,尽管它们都有效C# .NET用于MonoTouch用户:

public override void ViewDidAppear (bool animated)
{
    base.ViewDidAppear (animated);
    UIView.BeginAnimations ("fade in");
    UIView.SetAnimationDuration (1);
    imageView.Alpha = 1;
    UIView.CommitAnimations ();
}

7 个答案:

答案 0 :(得分:30)

最初将您的imageview的alpha设置为0 imageView.alpha = 0;

- (void)fadeInImage 
{
[UIView beginAnimations:@"fade in" context:nil];
    [UIView setAnimationDuration:1.0];
    imageView.alpha = 1.0;
    [UIView commitAnimations];

}

答案 1 :(得分:24)

将动画持续时间更改为您想要的长度。

UIImageView *myImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myImage.png"]];
myImageView.center = CGPointMake(100, 100);
myImageView.alpha = 0.0;
[self.view addSubview:myImageView];
[UIView animateWithDuration:5.0 animations:^{
     myImageView.alpha = 1.0;
}];

答案 2 :(得分:4)

UIViewController

中使用以下内容
// add the image view
[self.view addSubview:myImageView];
// set up a transition animation
CATransition *animate = [CATransition animation];
[animate setDuration:self.animationDelay];
[animate setType:kCATransitionPush];
[animate setSubtype:kCATransitionFade];
[animate setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

[[self layer] addAnimation:animate forKey:@"fade in"];

答案 3 :(得分:4)

这个简单的代码:

[UIView animateWithDuration:5.0 animations:^{
        theImage.alpha = 1.0;
    }];

UIImage位于视图中,并通过IBOutlet连接 您也可以在实用工具面板中设置alpha。

答案 4 :(得分:1)

我会使用UIView的+ transitionWithView:duration:options:animations:completion: 它非常高效和强大。

[UIView transitionWithView:imgView duration:1 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
    imgView.image = [UIImage imageNamed:@"MyImage"];
} completion:nil];

答案 5 :(得分:0)

您可以使用此代码:

淡入淡出动画:

self.yourComponent.alpha = 0.0f;
[UIView beginAnimations:@"fadeIn" context:nil];
[UIView setAnimationDuration:1.0]; // Time in seconds
self.yourComponent.alpha = 1.0f;

淡出动画:

self.yourComponent.alpha = 1.0f;
[UIView beginAnimations:@"fadeOut" context:nil];
[UIView setAnimationDuration:1.0]; // Time in seconds
self.yourComponent.alpha = 0.0f;

self.yourComponent可以是UIViewUIImageViewUIButton或任何其他组件。

答案 6 :(得分:0)

Swift版本

func fadeIn(){
    UIView.beginAnimations("fade in", context: nil);
    UIView.setAnimationDuration(1.0);
    imageView.alpha = 1.0;
    UIView.commitAnimations();
}