fade out image Animation in iphone [duplicate]

守給你的承諾、 提交于 2019-12-03 21:52:49
Nitin Gohel

Please visit this stack overflow question its iphone fading of images

- (void)viewDidLoad {
        imgView.animationImages=[NSArray arrayWithObjects:  
                                 [UIImage imageNamed:@"lori.png"],
                                 [UIImage imageNamed:@"miranda.png"],
                                 [UIImage imageNamed:@"taylor.png"],
                                 [UIImage imageNamed:@"ingrid.png"],
                                 [UIImage imageNamed:@"kasey.png"], 
                                 [UIImage imageNamed:@"wreckers.png"], nil];



        imgView.animationDuration=20.0;
        imgView.animationRepeatCount=0;
        [imgView startAnimating];
        [self.view addSubview:imgView];
        [imgView release];
        //The timers time interval is the imageViews animation duration devided by the number of images in the animationImages array. 20/5 = 4 
        NSTimer *timer = [NSTimer timerWithTimeInterval:4.0 
                                                  target:self 
                                                selector:@selector(onTimer) 
                                                userInfo:nil 
                                                 repeats:YES];

        [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
        [timer fire];

        [super viewDidLoad];
    }

    //It is important that the animation durations within these animation blocks add up to 4 
    //(the time interval of the timer). If you change the time interval then the time intervals 
    //in these blocks must also be changed to refelect the amount of time an image is displayed. 
    //Failing to do this will mean your fading animation will go out of phase with the switching of images.   

    -(void)onTimer{
            [UIView animateWithDuration:3.0 animations:^{
                imgView.alpha = 0.0; 
            }];
            [UIView animateWithDuration:1.0 animations:^{
                imgView.alpha = 1.0; 
            }];
        }

animate the alpha property of the view:

[UIView animateWithDuration:5 animations:^{
    imageview.alpha = 0;
}];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!