【发布时间】:2013-10-09 19:46:06
【问题描述】:
我已经为此苦苦挣扎了很长时间,但我就是不知道这里出了什么问题。我确实有一个想法——我认为不知何故,我正在添加并尝试制作动画的视图尚未包含在视图层次结构中,这就是为什么核心动画不会浪费周期来制作动画的原因。我在项目中成功地做了一些其他动画,但我在 ViewController 的 viewDidLoad 方法中运行它们。这是我的代码:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.opaque = NO;
self.backgroundColor = [UIColor colorWithWhite: 1.0 alpha: 0.7];
[self addTrack];
}
return self;
}
- (void)addTrack
{
//init the track here
UIView *track = [[UIView alloc] initWithFrame: CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)];
track.backgroundColor = [UIColor whiteColor];
[self addSubview: track];
//transform the track for its initial scale
float scaleFactorX = 0.01;
track.layer.anchorPoint = CGPointMake(0, 0);
track.layer.position = CGPointMake(0, 0);
track.transform = CGAffineTransformMakeScale(scaleFactorX, 1.0);
//animate the track here
[UIView animateWithDuration:8 delay:0.3 options:UIViewAnimationOptionCurveEaseOut
animations:^{
NSLog(@"animation is running.");
track.transform = CGAffineTransformIdentity;
}
completion:^(BOOL finished) {
NSLog(@"animation finished.");
}];
}
所以结果是“轨道”立即缩放到其原始大小。我还尝试在 didMoveToSuperview 方法中调用 addTrack,以便确保将包含视图添加到视图层次结构中,但结果相同。我尝试了该类中的其他动画,例如将 alpha 动画添加到包含视图但再次没有成功..
【问题讨论】:
标签: ios objective-c animation uiview