gpt4 book ai didi

ios - Segue延迟UIButton高亮显示

转载 作者:行者123 更新时间:2023-12-01 16:28:59 24 4
gpt4 key购买 nike

请检查编辑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的alpha

我也将其放在方法中,看是否可行。
catchButton.highlighted = YES;
[catchButton setImage:[UIImage imageNamed:@"chatHighlighted.png"] forState:UIControlStateSelected | UIControlStateHighlighted];
编辑2
我只是使用@selector(methodHere :)完全相同的方式设置了一个简单的UIButton,alpha随即更改。一定还有其他原因导致这种延迟吗?现在 super 困惑。
编辑3
通过注释掉上面 myButtonInvoked:方法的最后一行(请参见下文):
[self performSegueWithIdentifier:@"hereToThere" sender:self];
..设置 myButton.alpha = 0.4会立即(在视觉上)触发,问题解决了。为什么会发生这种情况,如何解决这个问题?

最佳答案

试试这个。

 [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

关于ios - Segue延迟UIButton高亮显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33284265/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com