禁用按钮淡入淡出图像

时间:2012-02-07 13:10:19

标签: iphone objective-c ios xcode

我有这个按钮,我想当你点击它时他将被禁用,屏幕上的图像会淡出,当下一个图像完成淡入时,按钮将再次启用。

我有这段代码:

-(IBAction)showPrev:(id)sender
{
    if (x != 0)
    {
        x=x-1;
        [self fadeOut];
        imgLettersView.image = [imagesArray objectAtIndex:x];
        [self fadeIn];
        btnNext.enabled = NO;
    }
    else
    {
        btnPrev.enabled = NO;
        btnNext.enabled = YES;
    }
lblshowx.text = [NSString stringWithFormat:@"%i",x];
}

-(void)fadeOut
{
    btnNext.enabled = NO;
    btnPrev.enabled = NO;
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1.2f];
    [self.imgLettersView setAlpha:0.0f];
    [UIView commitAnimations];
    [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(fadeIn) userInfo:nil repeats:NO];
}

-(void)fadeIn
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1.2f];
    [self.imgLettersView setAlpha:1.0f];
    [UIView commitAnimations];
    btnNext.enabled = YES;
    btnPrev.enabled = YES;
}

1 个答案:

答案 0 :(得分:2)

对fadeIn方法进行以下调整:

-(void)fadeIn
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1.2f];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(reEnableButton)];
    [self.imgLettersView setAlpha:1.0f];
    [UIView commitAnimations];
}

此外,将以下方法添加到同一控制器类中,您可以继续:

- (void) reEnableButton {
    btnNext.enabled = YES;
    btnPrev.enabled = YES;
}