gpt4 book ai didi

iphone - UIButton 在动画期间不交互

转载 作者:行者123 更新时间:2023-12-03 18:25:29 25 4
gpt4 key购买 nike

我正在尝试为 UIButton 制作动画。但在动画播放期间,没有与 UIButton 进行交互。预期的行为是能够在按钮移动时单击该按钮。这是 UIButton 和动画的代码片段:

UIImage *cloudImage = [UIImage imageNamed:@"sprite.png"];    
UIButton moveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[moveBtn setFrame:CGRectMake(0.0, 80.0, cloudImage.size.width, cloudImage.size.height)];
[moveBtn setImage:cloudImage forState:UIControlStateNormal];
[moveBtn addTarget:self action:@selector(hit:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:moveBtn];
CGPoint newLeftCenter = CGPointMake( 300.0f + moveBtn.frame.size.width / 2.0f, moveBtn.center.y);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:5.0f];
[UIView setAnimationRepeatCount:HUGE_VALF];
moveBtn.center = newLeftCenter;
[UIView commitAnimations];

hit 选择器仅显示 NSLog 以显示按钮是否对其做出响应。任何帮助将不胜感激。

最佳答案

尝试将动画选项设置为UIViewAnimationOptionAllowUserInteraction

[UIView animateWithDuration:.2
delay: 0
options: UIViewAnimationOptionAllowUserInteraction
animations:^{
// animation logic
}
completion:^(BOOL completed) {
// completion logic
}
];

关于iphone - UIButton 在动画期间不交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6346046/

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