我现在非常沮丧和恼火。
我花了一个小时调试一些代码,最后将它作为一个实验从switch语句中删除。在过去,我注意到一些代码根本不适用于交换机,现在我开始真的想知道答案:为什么不?
在这种情况下,我有一个简单的switch语句,包含3个case和一个默认情况。当我将工作代码保留在switch语句中时,如下所示,应用程序在“case 1bb”和“case 1c”输出语句之间崩溃。
当我将这些语句分解为它们自己独立的[self Animation1]和[self animation2]函数时,我没有得到一个错误。没有关于我向僵尸对象发送消息的抱怨,他们跑得很完美。
为什么呢? Objective-C是否根本不支持switch语句?
case 1:
NSLog(@"Case 0");
whopperImageView.frame=CGRectMake(0-whopperImageView.frame.size.width, 79, whopperImageView.frame.size.width, whopperImageView.frame.size.height);
whopperImageView.alpha=1;
[UIView animateWithDuration:5 animations:^(void){
whopperImageView.frame=CGRectMake(0, 79, whopperImageView.frame.size.width, whopperImageView.frame.size.height);
} completion:^(BOOL finished){
animationTimer=[NSTimer timerWithTimeInterval:5.0
target:self
selector:@selector(animationTimerFired:)
userInfo:nil repeats:NO];
[[NSRunLoop mainRunLoop] addTimer:animationTimer forMode:NSDefaultRunLoopMode];
}];
break;
case 2:
NSLog(@"Case 1");
chickenSandwichImageView.frame=CGRectMake(1024, 79, chickenSandwichImageView.frame.size.width, chickenSandwichImageView.frame.size.height);
chickenSandwichImageView.alpha=1;
NSLog(@"Case 1a");
[UIView animateWithDuration:5 animations:^(void){
NSLog(@"Case 1b");
chickenSandwichImageView.frame=CGRectMake(1024-chickenSandwichImageView.frame.size.width, 79, chickenSandwichImageView.frame.size.width, chickenSandwichImageView.frame.size.height);
NSLog(@"Case 1ba");
whopperImageView.alpha=0;
NSLog(@"Case 1bb");
} completion:^(BOOL finished){
NSLog(@"Case 1c");
animationTimer=[NSTimer timerWithTimeInterval:5.0
target:self
selector:@selector(animationTimerFired:)
userInfo:nil repeats:NO];
[[NSRunLoop mainRunLoop] addTimer:animationTimer forMode:NSDefaultRunLoopMode];
}];