IPhone: UIImageView исчезает в - Howto?
У меня есть 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 ();
}
Ответы
Ответ 1
Сначала установите альфа вашего изображения как 0 как imageView.alpha = 0;
- (void)fadeInImage
{
[UIView beginAnimations:@"fade in" context:nil];
[UIView setAnimationDuration:1.0];
imageView.alpha = 1.0;
[UIView commitAnimations];
}
Ответ 2
Измените продолжительность анимации на нужную вам длину.
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;
}];
Ответ 3
Используйте ниже в 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"];
Ответ 4
этот простой код:
[UIView animateWithDuration:5.0 animations:^{
theImage.alpha = 1.0;
}];
UIImage
находится в представлении и подключается через IBOutlet
вы также можете установить альфа из панели служебных программ.
Ответ 5
Я бы использовал UIView + transitionWithView: duration: options: animations: completion:
Он очень эффективен и эффективен.
[UIView transitionWithView:imgView duration:1 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
imgView.image = [UIImage imageNamed:@"MyImage"];
} completion:nil];
Ответ 6
Вы можете использовать этот код:
Fade In Animation:
self.yourComponent.alpha = 0.0f;
[UIView beginAnimations:@"fadeIn" context:nil];
[UIView setAnimationDuration:1.0]; // Time in seconds
self.yourComponent.alpha = 1.0f;
Анимация Fade Out:
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
или любым другим компонентом.
Ответ 7
Быстрая версия
func fadeIn(){
UIView.beginAnimations("fade in", context: nil);
UIView.setAnimationDuration(1.0);
imageView.alpha = 1.0;
UIView.commitAnimations();
}