繁体   English   中英

动画UISegmentedControl的框架

[英]Animating the frame of a 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)];
    }];
});

发生的情况是尺寸立即改变,但是位置动画正确。 为什么这样做,并且有任何解决方法?

如果需要,在动画块中告诉分段控件进行布局。

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

看来您可以通过手动调整动画块内UISegmentedControl的所有子视图的大小来解决此问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM