[英]UISegmentedControl not responding within UIView
I have a UIView
property named viewToFade
that contains a UISegmentedControl
. 我有一个名为viewToFade
的UIView
属性,其中包含一个UISegmentedControl
。 When I animate the UIView
(so it appears on tapping and gradually fades), the UISegmentedControl
doesn't respond to touches. 当我为UIView
设置动画(使其出现在轻敲并逐渐淡入淡出)时, UISegmentedControl
不响应触摸。 Here's the code I'm using: 这是我正在使用的代码:
-(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];
}
What am I doing wrong? 我究竟做错了什么?
(In case it's relevant, I'll say that the UIView
and the UISegmentedControl
are both created in the xib file.) (如果相关,我会说UIView
和UISegmentedControl
都在xib文件中创建。)
EDIT: I figured out a way to deal with the problem, which was to rewrite the code as follows: 编辑:我想出了一种方法来解决该问题,这是重写代码,如下所示:
-(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;
}];
}
I played around with this in a sample project and could duplicate your results - nothing I did even animating (in my case) a button itself rendered it immune to touches. 我在一个示例项目中进行了尝试,并且可以复制您的结果-我什至没有做动画(就我而言),按钮本身使它不受触摸。 However in my limited test I was able to see that it did respond to highlighting. 但是,在我的有限测试中,我能够看到它确实对突出显示有所响应。
I just tested the following (using a UIBuutton, suppose the same thing will work for segmented control): 我刚刚测试了以下内容(使用UIBuutton,假设相同的方法适用于分段控件):
add a transparent view over your button, and add a gesture recognizer to it, just before the animation 在动画之前,在按钮上添加透明视图,并向其添加手势识别器
have the actionMethod of the tap recognizer change the highlighting of the button on, then dispatch a block to turn it off in 100ms or so (you could get fancier if you actually intercept touches). 让敲击识别器的actionMethod更改按钮的高亮显示,然后分派一个块以在100毫秒左右的时间内将其关闭(如果您实际上拦截了触摸,则可能会更有趣)。
in addition to changing the highlighting, send something like this to the control (again using a button) : 除了更改突出显示之外,还向控件发送类似的内容(再次使用按钮):
[tapButton sendActionsForControlEvents:UIControlEventTouchUpInside];
It appears the control is responsive to such things during the animation. 看起来控件在动画过程中对这些事情有所响应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.