我有一个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 ();
}
答案 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
可以是UIView
,UIImageView
,UIButton
或任何其他组件。
答案 6 :(得分:0)
Swift版本
func fadeIn(){
UIView.beginAnimations("fade in", context: nil);
UIView.setAnimationDuration(1.0);
imageView.alpha = 1.0;
UIView.commitAnimations();
}