这可能听起来真的很棒,但我已经花了一整天的时间来解决这个问题并且会感激一些帮助.
你看我有一种方法,我在游戏玩法中不止一次打电话.如果我使用[self myMethod];它然后它工作一次.然后当我再次调用它时,方法中的动画不再开始了.
我需要的是将"自我"替换为可以"分配"和"释放"以使我的动画有效的替代方案.
我试过了;
@implementation gameViewController
gameViewController *object = [[gameViewController alloc] init];
[object myMethod];
Run Code Online (Sandbox Code Playgroud)
然而,上面的自我替代甚至没有调用该方法.我不知道我做错了什么,它假设像"自我"一样工作.
我错过了什么吗?你如何让班级的对象像"自我"一样工作?
非常感谢.
这是我的代码的更详细的外观;
[self explosionAnimations];
- (void) explosionAnimations
{
UIImage *image = [UIImage imageNamed: @"Yellow Explosion.png"];
[bomb setImage:image];
[UIView beginAnimations:@"bomb1ExplosionIncrease" context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
bomb.transform = CGAffineTransformMakeScale(3.4, 3.4);
[UIView commitAnimations];
}
Run Code Online (Sandbox Code Playgroud)
setImage每次都运行正常.但是动画停止了对方法的第二次调用.在控制台中,它记录"动画完成",图像没有任何变化.
这让我相信,某种"自我"认为动画已经完成,并且不会再费心去做了.所以我认为一个新的"分配"可能会让它清醒.
这个问题与"自我"没有任何关系.问题是你在动画中设置了变换,然后当你再次运行它时,你正在设置相同的变换,所以它什么都不做.您需要将帧重置为新帧,然后在再次执行动画之前将变换设置回标识变换.此外,您应该使用基于块的动画.我不确定这是最好的方法,但这对我有用(如果你关闭了自动布局).
- (void)explosionAnimations {
UIImage *image = [UIImage imageNamed: @"Yellow Explosion.png"];
[self.bomb setImage:image];
[UIView animateWithDuration:.5 animations:^{
self.bomb.transform = CGAffineTransformMakeScale(3.4, 3.4);
} completion:^(BOOL finished) {
CGRect newFrame = self.bomb.frame;
self.bomb.transform = CGAffineTransformIdentity;
self.bomb.frame = newFrame;
}];
}
Run Code Online (Sandbox Code Playgroud)
如果您在打开了自动布局的应用程序中执行此操作(默认情况下),那么我不会使用转换,只需通过调整其高度和宽度约束来调整图像视图的宽度和高度.因此,在此方法中,您应该将IBOutlet设置为在IB中进行的高度和宽度约束,然后在动画块中更改它们的常量值:
[UIView animateWithDuration:.5 animations:^{
self.heightCon.constant = self.heightCon.constant * 3.4;
self.widthCon.constant = self.widthCon.constant * 3.4;
[self.view layoutIfNeeded];
}];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
196 次 |
| 最近记录: |