iPhone:UIImageView淡入淡出-如何?
我有一个iPhone:UIImageView淡入淡出-如何?,iphone,ios,ipad,uiimageview,xamarin.ios,Iphone,Ios,Ipad,Uiimageview,Xamarin.ios,我有一个UIImageView,我想淡入 有没有办法在基础UIViewController上启用该功能 我已经为MonoTouch用户翻译了最简单的答案,C#NET: public override void ViewDidAppear (bool animated) { base.ViewDidAppear (animated); UIView.BeginAnimations ("fade in"); UIView.SetAnimationDuration (1);
UIImageView
,我想淡入
有没有办法在基础UIViewController
上启用该功能
我已经为MonoTouch
用户翻译了最简单的答案,C#NET
:
public override void ViewDidAppear (bool animated)
{
base.ViewDidAppear (animated);
UIView.BeginAnimations ("fade in");
UIView.SetAnimationDuration (1);
imageView.Alpha = 1;
UIView.CommitAnimations ();
}
将动画持续时间更改为所需的长度
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;
}];
最初将imageview的alpha设置为0,即
imageview.alpha=0代码>
- (void)fadeInImage
{
[UIView beginAnimations:@"fade in" context:nil];
[UIView setAnimationDuration:1.0];
imageView.alpha = 1.0;
[UIView commitAnimations];
}
在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"];
这个简单的代码:
[UIView animateWithDuration:5.0 animations:^{
theImage.alpha = 1.0;
}];
ui图像
位于视图中,并通过IBOutlet连接
您还可以从实用程序面板设置alpha。我将使用UIView的+transitionWithView:duration:options:animations:completion:
它是非常有效和强大的
[UIView transitionWithView:imgView duration:1 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
imgView.image = [UIImage imageNamed:@"MyImage"];
} completion:nil];
您可以使用以下代码:
淡入动画:
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.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。您的组件可以是UIView
、UIImageView
、UIButton
或任何其他组件。Swift版本
func fadeIn(){
UIView.beginAnimations("fade in", context: nil);
UIView.setAnimationDuration(1.0);
imageView.alpha = 1.0;
UIView.commitAnimations();
}
是否可以只设置UIImageView的动画而不设置UIView的动画?(如果是这样的话,那是怎么回事?)对我来说:我从UI编辑器中添加了一个UIImageView
,之后(我需要淡出imageview)只添加了示例的最后3行(alpha=0.0),就可以了!