Reputation: 2207
I have a UIView
property named viewToFade
that contains a UISegmentedControl
. When I animate the UIView
(so it appears on tapping and gradually fades), the UISegmentedControl
doesn't respond to touches. 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.)
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;
}];
}
Upvotes: 1
Views: 572
Reputation: 41632
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):
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).
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.
Upvotes: 1