1

我有一个UIView名为的属性viewToFade,其中包含一个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];
}

我究竟做错了什么?

(如果相关,我会说 theUIView和 theUISegmentedControl都是在 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;
                 }];
}
4

1 回答 1

1

我在一个示例项目中玩过这个,可以复制你的结果——我什至没有做任何动画(在我的例子中)一个按钮本身使它不受触摸的影响。然而,在我有限的测试中,我能够看到它确实对突出显示有反应。

我刚刚测试了以下内容(使用 UIBuutton,假设同样的事情适用于分段控制):

  • 在按钮上添加一个透明视图,并在动画之前为其添加手势识别器

  • 让点击识别器的 actionMethod 更改按钮的突出显示,然后调度一个块以在 100 毫秒左右将其关闭(如果你真的拦截触摸,你会变得更漂亮)。

  • 除了更改突出显示之外,还向控件发送类似这样的内容(再次使用按钮):

    [tapButton sendActionsForControlEvents:UIControlEventTouchUpInside];
    

似乎控件在动画期间对此类事情做出了响应。

于 2012-09-07T13:34:44.610 回答