fade in an image in xcode automatically

て烟熏妆下的殇ゞ 提交于 2019-12-24 18:25:11

问题


Hello I am able to fade an image out automatically. How would I manage to fade the image IN automatically.

Here is my code.

.h

@property (assign) IBOutlet UIImageView *cbizFadeImage;

.m

- (void)viewDidLoad {
//Fade Image Out
CGRect aboutNicheImageFrame = cbizFadeImage.frame;
aboutNicheImageFrame.origin.y = self.view.bounds.size.height;


// iOS4+
[UIView animateWithDuration:0.5
                      delay:2.0
                    options: UIViewAnimationCurveEaseOut
                 animations:^{
                     cbizFadeImage.alpha = 0;

                 }
                 completion:^(BOOL finished){
                     NSLog(@"Done!");
                 }];
}

Ok I was able to fade an image in by changing the CurveEaseOut to CurveEaseIn. However now I would like to fade the image out. So the image would first ease in then It would then ease out. Would I use an if statement?


回答1:


I was able to use the UIViewAnimationCurveEaseInOut.




回答2:


Instead of UIViewAnimationCurveEaseInOut, use this for options:

options:UIViewAnimationOptionCurveEaseOut



回答3:


I think what your really asking for is UIViewKeyframeAnimationOptionAutoreverse Used like this...

Image.alpha = 0;
[UIView animateKeyframesWithDuration:5.0 delay:0.0        options:UIViewKeyframeAnimationOptionAutoreverse |     UIViewKeyframeAnimationOptionRepeat animations:^{
[UIView addKeyframeWithRelativeStartTime:0.9 relativeDuration:0.0     animations:^{
Image.alpha = 1;
}];
[UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.0     animations:^{
Image.alpha = 0;
}];
} completion:nil];


来源:https://stackoverflow.com/questions/12677895/fade-in-an-image-in-xcode-automatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!