2011-02-24 84 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