让按钮消失和收割者



我有一个应用程序,其中有一个IBAction,可以识别点击手势,我希望点击可以使屏幕上的按钮消失,然后在点击后重新出现。

- (IBAction)showFullScreen:(UITapGestureRecognizer *)sender {




}

我知道这可能是一部动画。我有4个按钮,UIImageView是我需要单独显示的

你的意思是希望他们连续运行两个动画?尝试:

[UIView animateWithDuration:1 animations:^{
    view1.layer.opacity = 0;
    view2.layer.opacity = 0;
} completion:^(BOOL finished){
    [UIView animateWithDuration:1 animations:^{
        view1.layer.opacity = 1;
        view2.layer.opactiy = 1;
    }];
}];

您需要包含核心图形才能访问图层属性。

#import <QuartzCore/QuartzCore.h>

您的另一个选择是将关键帧动画与CAKeyframeAnimation 一起使用

试试这个:

-(void)showButton {
self.button.hidden = NO;
}

-(IBAction) hidebutton{    
[self performSelector:@selector(showButton) withObject:nil
afterDelay:1.5];}

隐藏mybutton.hidden=是;显示mybutton.hidden=否;

在我看来,你有两个步骤:第一次点击会使按钮消失并显示图像,seocnd点击会使其反转。由于alpha值是浮点值,并且浮点值不太可靠,无法使用==进行比较,所以我倾向于使用外部bool属性来跟踪这类事情。(实际上,我还没有看到将其用于alpha的很多问题,所以可以随意检查alpha变量)

if(buttonsShowing)//(button1.view.opacity==1)
{
    [UIView animateWithDuration:1 animations:^{
        button1.view.opacity = 0;
        button2.view.opacity = 0;
        button3.view.opacity = 0;
        imageView.opacity = 1;
    }];
}
}
else
{
    [UIView animateWithDuration:1 animations:^{
        button1.view.opacity = 1;
        button2.view.opacity = 1;
        button3.view.opacity = 1;
        imageView.opacity = 0;
    }];
}
buttonsShowing=!buttonsShowing;

最新更新