【发布时间】:2013-01-08 15:03:31
【问题描述】:
我有一个 UISegmentedControl 像模态窗口一样显示/隐藏。最初它没有选定的段。在 IB 中,Value Changed 事件连接到方法 - (IBAction)cardClassificationChanged:(UISegmentedControl *)sender。这是那个方法:
- (IBAction)cardClassificationChanged:(UISegmentedControl *)sender
{
NSLog(@"%d", sender.selectedSegmentIndex);
// block for updating the categorization of current card asynchronously
[self.cardActionSheet hideWithAnimation];
}
如果我注释掉最后一行(对 -hideWithAnimation 的调用),选择会按预期更改,一切正常。但是,通过调用该动画方法,UISegmentedControl 选择在动画之前不会在视觉上发生变化。这是 hideWithAnimation 方法:
- (void)hideWithAnimation
{
CATransition *animation = [CATransition animation];
animation.type = kCATransitionFade;
animation.duration = globalAnimationLength;
[self.layer addAnimation:animation forKey:nil];
self.hidden = YES;
}
下次出现此视图时(通过触摸手势),UISegmentedControl 将选择正确的段。
似乎我不应该为 UISegmentedControl 调用 setNeedsDisplay,但即使我在 cardClassificationChanged 方法或 hideWithAnimation 方法中试验它,它也不会刷新。
我显然遗漏了与 UI 更新相关的内容,我需要调用什么来在动画之前更新 UISegmentedControl 选择?
【问题讨论】:
-
-hideWithAnimation方法永远不会在-cardClassificationChanged:处调用,而是调用-hideCardActionSheet:。你能检查一下复制的代码并修复它吗? -
你是对的,很抱歉造成混乱。 -hideCardActionSheet 有一些其他的逻辑/处理,然后调用 -hideWithAnimation。当我能够回到那台机器时,我会更新。目前,cardClassificationChanged 内部的动画或逻辑没有任何问题,我的问题是 UISegmentedControl 没有在视觉上更新以反映选择。
-
@A-Live 已编辑,感谢您指出这一点。
标签: ios