0

重複の可能性:
iPhoneの画像のフェード

フェードアウト アニメーションを一連の画像 (画像の配列) に実装するにはどうすればよいですか。画像が 1 つずつ表示されます。以下のコードを使用すると、単純なスライドショーのみが表示されます。

NSArray *imagearray = [NSArray arrayWithObjects:
                             [UIImage imageNamed:@"image1.png"],
                             [UIImage imageNamed:@"imag2.png"],[UIImage imageNamed:@"imag3.png"],[UIImage imageNamed:@"imag4.png"],[UIImage imageNamed:@"imag5.png"],[UIImage imageNamed:@"imag6.png"],[UIImage imageNamed:@"imag7.png"],nil];
imageview.animationImages=imagearray;


imageview.animationDuration = 10.00;  

imageview.animationRepeatCount = 0;

[imageview startAnimating];

フェード効果を実装するにはどうすればよいですか?

4

2 に答える 2

3

ビューのアルファ プロパティをアニメーション化します。

[UIView animateWithDuration:5 animations:^{
    imageview.alpha = 0;
}];
于 2012-11-24T10:29:10.980 に答える
2

このスタック オーバーフローの質問にアクセスしてください。そのiPhone の画像のフェード

- (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; 
            }];
        }
于 2012-11-24T10:30:58.933 に答える