2011-02-24 85 views
1

我有我想要进行动画使用以下(简化,但功能)代码的框架一个UISegmentedControl:动画一个UISegmentedControl的框架

UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"item1", @"item2", nil]]; 
[seg setFrame:CGRectMake(0, 300, 100, 50)]; 
[self addSubview:seg]; 

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(),^{ 
    [UIView animateWithDuration:5.0 animations:^{ 
     [seg setFrame:CGRectMake(100, 0, 400, 50)]; 
    }]; 
}); 

什么情况立即大小的变化,但该位置正确动画。为什么它这样做,并有任何解决方法?

回答

0

看来你可以通过手动调整动画块中UISegmentedControl的所有子视图来解决这个问题。

6

如果需要在动画块中告诉分段控制布局。

[UIView animateWithDuration:.25f animations:^{ 
    self.segmentedControl.frame = frame; 
    [self.segmentedControl layoutIfNeeded]; 
}]; 
+0

这真的应该是被接受的答案。比子视图摆弄更强大。 – 2014-04-17 15:26:04