繁体   English   中英

UISegmentedControl在UIView中没有响应

[英]UISegmentedControl not responding within UIView

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

我究竟做错了什么?

(如果相关,我会说UIViewUISegmentedControl都在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,假设相同的方法适用于分段控件):

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

  • 让敲击识别器的actionMethod更改按钮的高亮显示,然后分派一个块以在100毫秒左右的时间内将其关闭(如果您实际上拦截了触摸,则可能会更有趣)。

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

     [tapButton sendActionsForControlEvents:UIControlEventTouchUpInside]; 

看起来控件在动画过程中对这些事情有所响应。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM