我有一个名为 viewToFade
的 UIView
属性,它包含一个 UISegmentedControl
。当我为 UIView
设置动画时(因此它在点击时出现并逐渐消失),UISegmentedControl
不响应触摸。这是我正在使用的代码:
-(void)fadeView
{
self.viewToFade.alpha=1;
self.viewToFade.hidden=NO;
//When I comment the following lines out, everything is fine--the `UISegmentedControl` responds as it should.
//But when I include them, the `UISegmentedControl` doesn't register changes/taps.
[UIView animateWithDuration:0.3
delay: 3.0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
self.viewToFade.alpha = 0.0;
}
completion:nil];
}
我做错了什么?
(如果相关,我会说 UIView
和 UISegmentedControl
都是在 xib 文件中创建的。)
编辑:我想出了一个解决问题的方法,就是重写代码如下:
-(void)fadeView
{
self.viewToFade.alpha=1;
self.viewToFade.hidden=NO;
[self performSelector:@selector(disneyfy) withObject:nil afterDelay:(3)];
}
-(void)disneyfy
{
[UIView animateWithDuration:0.3
animations:^{
self.viewToFade.alpha = 0.0;
}];
}
最佳答案
我在一个示例项目中尝试过这个并且可以复制您的结果 - 我什至没有做任何动画(在我的例子中)按钮本身使其不受触摸影响。然而,在我有限的测试中,我能够看到它确实响应突出显示。
我刚刚测试了以下内容(使用 UIBuutton,假设同样的事情适用于分段控制):
在您的按钮上添加一个透明 View ,并在动画之前为其添加一个手势识别器
让点击识别器的 actionMethod 更改按钮的突出显示,然后分派(dispatch)一个 block 以在 100 毫秒左右将其关闭(如果您实际拦截触摸,您可能会更漂亮)。
除了更改突出显示之外,还向控件发送这样的内容(再次使用按钮):
[tapButton sendActionsForControlEvents:UIControlEventTouchUpInside];
看起来控件在动画期间对这些事情有反应。
关于iphone - UISegmentedControl 在 UIView 中没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12311481/