我一直在苦苦挣扎很久,我只是无法找到这里出了什么问题。我确实有一个想法 - 我认为我添加并试图进行动画制作的视图还没有包含到视图层次结构中,这就是为什么核心动画不会浪费周期来进行动画制作。我在项目中成功完成了其他一些动画,但是我在ViewController的viewDidLoad方法中运行它们。这里是我的代码:UIView动画立即完成
- (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动画,但没有再次成功。
这是一个* UIViewController *的方法,我想在我的视图中运行动画.. –
只是尝试运行... – preetam
是的,这一个解决了它谢谢。但这不是我真正想要的,我的意思是我想在包含类中启动动画。没关系,我现在就离开它,希望我找到另一种解决方案。 –