请检查编辑3
我有一个UIButton,当我按下它时,我需要看到它立即变灰。我使用这段代码作为声明:
UIButton *myButton;
myButton = [[UIButton alloc] init]; //[UIButton buttonWithType:UIButtonTypeCustom];
myButton.frame = CGRectMake(132, 375, 40, 40);
buttonImage = [UIImage imageNamed:@"chat.png"];
[myButton setImage:buttonImage forState:UIControlStateNormal];
[myButton addTarget:self action:@selector(myButtonInvoked:)forControlEvents:UIControlEventTouchDown];
[cell.contentView addSubview:myButton];
下面是按钮触发的方法
- (void) myButtonInvoked:(id)sender
{
UIButton *catchButton = (UIButton *)sender;
CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition];
[UIView animateWithDuration:5
delay:0.0
options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveEaseInOut
animations:^{
catchButton.alpha = 0.4;
catchButton.enabled = NO;
}
completion:NULL];
[self performSegueWithIdentifier:@"hereToThere" sender:self];
}
我使用UIAnimation代码在按下按钮时使按钮变灰,注意它的延迟为0,但是UIButton正在因延迟而变灰。我怎样才能摆脱这个延误呢?我需要myButton马上把头发灰掉。
编辑
我现在尝试添加commentsButton.showsTouchWhenHighlighted = YES;
,也尝试为UIControlStateNormal中的按钮设置图像,并将其高亮显示为相同但灰色的图像。这也延迟了。
但是,如果我在方法的开头放置一个NSLog
,我可以看到它在按下按钮时立即打印,那么为什么它不能立即更新图像呢?我已经用以下方法尝试了所有的方法来使它发挥作用:
( A)突出 B)图像的变化 ( C) UIButtonα的变化
我也把它放在方法中,看它是否有效。
catchButton.highlighted = YES;
[catchButton setImage:[UIImage imageNamed:@"chatHighlighted.png"] forState:UIControlStateSelected | UIControlStateHighlighted];
编辑2
我只是使用@selector(methodHere:)设置了一个简单的methodHere,方法完全相同,并且alpha会立即发生变化。一定是其他原因造成了这一延误?现在太迷茫了。
编辑3,方法是注释掉上面myButtonInvoked:
方法中的最后一行(参见下面):
[self performSegueWithIdentifier:@"hereToThere" sender:self];
。。立即设置myButton.alpha = 0.4
触发器(直观地),问题就解决了。为什么会发生这种情况,我怎样才能解决这个问题呢?
发布于 2015-10-22 08:03:34
试试这个。
[UIView animateWithDuration:0.0 //0.0
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut//UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat |
animations:^{
catchButton.alpha = 0.4;
catchButton.enabled = NO;
}
completion:NULL];
延迟发生:因为您正在使用
animateWithDuration = 5 second
https://stackoverflow.com/questions/33284265
复制相似问题