gpt4 book ai didi

ios - UIView 动画立即完成

转载 作者:行者123 更新时间:2023-12-01 17:55:10 26 4
gpt4 key购买 nike

我已经为此苦苦挣扎了很长时间,我只是无法找出这里出了什么问题。我确实有一个想法——我认为不知何故,我正在添加并尝试制作动画的 View 尚未包含在 View 层次结构中,这就是为什么核心动画不会浪费周期来制作动画的原因。我在项目中成功地做了一些其他动画,但我在 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,以便确保将包含 View 添加到 View 层次结构中但结果相同。我在该类中尝试了其他动画,例如将 alpha 动画添加到包含 View 但再次没有成功..

最佳答案

加载 View 后尝试调用动画,以便您可以看到它。

-(void)viewDidAppear:(BOOL)animated
{
[self addTrack];
}

关于ios - UIView 动画立即完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19270588/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com