【发布时间】:2014-04-22 04:58:10
【问题描述】:
在viewDidAppear我调用以下代码:
MyView *myView = [[MyView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
myView.backgroundColor = [UIColor clearColor];
[self.view addSubview:myView];
[myView setProgress:0.3 animated:YES];
最后一行调用了这个方法:
- (void)setProgress:(CGFloat)progress animated:(BOOL)animated {
self.innerPie.hidden = NO;
self.innerPie.strokeEnd = progress;
CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
pathAnimation.duration = 3.0;
pathAnimation.fromValue = [NSNumber numberWithFloat:self.progress];
pathAnimation.toValue = [NSNumber numberWithFloat:progress];
[self.innerPie addAnimation:pathAnimation forKey:@"strokeEndAnimation"];
self.progress = progress;
}
然而,当我加载模拟器时,动画从不开始。为什么?如图所示,视图是否尚未出现?
奇怪的是,如果我使用 dispatch_after 并延迟 0 秒(即时),它会显示。
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[myView setProgress:0.8 animated:YES];
});
我做错了什么?
【问题讨论】:
标签: ios objective-c cocoa-touch core-animation