单击后,我想让按钮逐渐消失。我知道我可以使用
_myButon.hidden = TRUE;
...完全隐藏按钮,但感觉突然而且不和谐。我也知道我可以按顺序降低alpha或其他东西,但不知道如何在短时间内自动发生这种情况。
有人可以用最简单的方法点击按钮后给我一个提示吗?我希望效果看起来像是来自powerpoint演示文稿的简单“淡出”或其他东西:)
谢谢!
答案 0 :(得分:8)
[UIView animateWithDuration:0.5 animations:^{
_myButton.alpha = 0;
}];
答案 1 :(得分:4)
不要删除按钮,只需将其隐藏即可。考虑到所有建议,你得到:
[UIView animateWithDuration:0.5
animations:^{ _myButton.alpha = 0; }
completion:^(BOOL finished){ _myButton.hidden = YES; }
];
答案 2 :(得分:2)
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
_myButton.alpha = 0.0f;
[UIView commitAnimations];
替代地
[UIView animateWithDuration:1.0 animations:^{
_myButton.alpha = 0.0f;
}];
答案 3 :(得分:1)
只是减少alpha不会使您的按钮完全从视图中删除。对于用户来说,它看起来会消失,但它仍然存在。他们可能仍然会在不知情的情况下意外地点击它。所以你可以做的是做一个计时器,在它消失之后将它从视图中删除。
...
//alpha animation
//remove from view
timer1 = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(hideMyButton) userInfo:nil repeats:NO];
}
-(IBAction) hideMyButton
{
[_myButon removeFromSuperview];
}