I have a UISegmentedControl that is shown/hide like a modal window. Initially it does not have a selected segment. In IB, the Value Changed event is wired to the method – (IBAction)cardClassificationChanged:(UISegmentedControl *)sender. Here is that method:
- (IBAction)cardClassificationChanged:(UISegmentedControl *)sender
{
NSLog(@"%d", sender.selectedSegmentIndex);
// block for updating the categorization of current card asynchronously
[self.cardActionSheet hideWithAnimation];
}
If I comment out the last line (the call to -hideWithAnimation), the selection changes as expected, everything works. However, with the call to that animation method, the UISegmentedControl selection will not visually change before the animation. Here is the hideWithAnimation method:
- (void)hideWithAnimation
{
CATransition *animation = [CATransition animation];
animation.type = kCATransitionFade;
animation.duration = globalAnimationLength;
[self.layer addAnimation:animation forKey:nil];
self.hidden = YES;
}
The next time this view appears (from a touch gesture), the UISegmentedControl will have the correct segment selected though.
It seems like I should not have to call setNeedsDisplay for the UISegmentedControl, but even when I experiment with it in the cardClassificationChanged method or the hideWithAnimation method, it does not refresh.
I’m obviously missing something related to the UI update, what do I need to call to update the UISegmentedControl selection before the animation?
I suggest you should use UIKit animations for fading out your control. Try the following code