【发布时间】:2015-02-15 15:52:36
【问题描述】:
我想创建一个仅显示 5 秒然后消失的按钮。用户必须在按钮消失之前单击它。所以我使用 animationWithDuration 将 alpha 设置为 1,然后将其设置回 0。这是我的代码...
__block UIButton *showButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 150, 40)];
[showButton setTitle:@"go to next page!" forState:UIControlStateNormal];
showButton.alpha = 0;
[showButton addTarget:self action:@selector(showButtonClick) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:showButton];
[UIView animateWithDuration:1
delay:0
options: UIViewAnimationOptionCurveEaseInOut
animations:^{
showButton.alpha = 1.0;
}
completion:nil];
[UIView animateWithDuration:0.5
delay:3.0
options: UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction
animations:^{
showButton.alpha = 0.0;
}
completion:^(BOOL finished){
[showButton removeFromSuperview];
showButton = nil;
}];
-(void)showButtonClick{
NSLog(@"click")
}
但无法调用 showButtonClick。我做错了什么?
【问题讨论】:
-
你什么时候点击按钮的?在按钮完全可见之后还是在第一个动画期间可见?
-
按钮完全可见后。延迟的事情似乎不起作用。