我有一个名为
的方法- (void) startAnimationForTime : (NSNumber* ) time {
我从我的代码中的其他地方打电话。它在我第一次调用该方法时效果很好,但是当我用其他一些持续时间调用它时,它仍然会以之前的持续时间动画。动画速度不会改变。 假设我是第一次这样调用我的方法...
[self performSelectorOnMainThread:@selector(startAnimationForTime:) withObject:[NSNumber numberWithFloat:20.0] waitUntilDone:NO];
如果我从其他地方称之为,
[self performSelectorOnMainThread:@selector(startAnimationForTime:) withObject:[NSNumber numberWithFloat:10.0] waitUntilDone:NO];
预计动画速度会发生变化,但事实并非如此。 我在这里发布我的动画方法......
在我的代码中的其他一些方法中,
animator1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"beach_bg.png"]];
animator2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"beach_bg.png"]];
animator1.frame = CGRectMake(0,-bgHeight,320,bgHeight);
animator2.frame = CGRectMake(0,0,320,bgHeight);
- (void) startAnimationForTime : (NSNumber*) time {
animator1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"beach_bg.png"]];
animator2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"beach_bg.png"]];
[self.view addSubview:animator1];
[self.view addSubview:animator2];
[self.view addSubview:playTime];
[self.view addSubview:pauseButton];
[self.view addSubview:bgImageView];
animator1.frame = CGRectMake(0,-bgHeight,320,bgHeight);
animator2.frame = CGRectMake(0,0,320,bgHeight);
[UIView animateWithDuration:[time floatValue]
delay:0.0
options:UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear
animations:^{
animator2.transform = CGAffineTransformMakeTranslation(0, bgHeight); }
completion:^(BOOL fin) { if (fin){}}];
[UIView animateWithDuration:[time floatValue]
delay:0.0
options:UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear
animations:^{
animator1.transform = CGAffineTransformMakeTranslation(0, bgHeight); }
completion:^(BOOL fin) { if (fin){}}];
}
我第二次尝试使用这个方法,
animator1.frame = [[animator1.layer presentationLayer]frame];
animator2.frame = [[animator2.layer presentationLayer]frame];
这会让我获得animator1
和animator2
的当前帧。但这也不起作用。
我很难坚持这个......
任何帮助都将非常感谢....
提前致谢..
答案 0 :(得分:0)
请将此代码放在
之前 animator1.frame = CGRectMake(0,-bgHeight,320,bgHeight);
animator2.frame = CGRectMake(0,0,320,bgHeight);
这个
[self.view addSubview:animator1];
[self.view addSubview:animator2];
[self.view addSubview:playTime];
[self.view addSubview:pauseButton];
[self.view addSubview:bgImageView];
并尝试制作动画。希望这有帮助