iphone - UISegmentedControl 在 UIView 中没有响应

标签 iphone ios uisegmentedcontrol

我有一个名为 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,假设同样的事情适用于分段控制):

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

  • 让点击识别器的 actionMethod 更改按钮的突出显示,然后分派(dispatch)一个 block 以在 100 毫秒左右将其关闭(如果您实际拦截触摸,您可能会更漂亮)。

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

    [tapButton sendActionsForControlEvents:UIControlEventTouchUpInside];
    

看起来控件在动画期间对这些事情有反应。

关于iphone - UISegmentedControl 在 UIView 中没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12311481/

相关文章:

iphone - 向 UIMapView 添加可点击注释

iphone - NSPredicate 过滤空格和字母数字

ios - iOS 7中不显示社交 View 的默认警报

ios - 自定义框架适用于 iPhone 4S/5 和 iPad 模拟器,不适用于 iPhone 5s/6/6Plus/6s/6sPlus

swift - 带有分段 Controller 的 UITableView 不会立即显示数据 - Swift

iphone - NSCoder encode Object : and encodeObject:forkey:? 有什么区别

iphone - 如何从 Core Data 中的 UIImageView 保存 UIImage

ios - 保持按索引更新的有序字典值数组

ios - 更改 UISegmentControl 中所选项目的颜色

ios - 如何删除分段控件旁边的白条