我这里有一个奇怪的问题。我为简单的页面翻转设置了两个动画。然后我有一个随机生成1或0的按钮。如果数字为0则执行一个动画,如果它为1则执行另一个动画。
我所看到的问题是,这一切都在模拟器上运行良好,但在设备上,如果随机数为0,它就不会执行动画。
任何线索?
-(IBAction)pageTurn:(id)sender {
int randomNumber = arc4random() %2;
NSLog(@"randomNumber = %d", randomNumber);
if (randomNumber == 0) {
[self turnPageForward];
} else {
[self turnPageBackward];
}
}
-(void)turnPageForward {
NSArray *myImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"PageTurnOne.png"],
[UIImage imageNamed:@"PageTurnTwo.png"],
[UIImage imageNamed:@"PageTurnThree.png"],
[UIImage imageNamed:@"PageTurnFour.png"],
[UIImage imageNamed:@"PageTurnFive.png"],
[UIImage imageNamed:@"PageTurnSix.png"],
[UIImage imageNamed:@"PageTurnSeven.png"],
[UIImage imageNamed:@"PageTurnEight.png"],
[UIImage imageNamed:@"PageTurnNine.png"],
nil];
UIImageView *myAnimatedView = [UIImageView alloc];
[myAnimatedView initWithFrame:CGRectMake(0, 0, 320, 480)];
myAnimatedView.animationImages = myImages;
myAnimatedView.animationDuration = .5; // seconds
myAnimatedView.animationRepeatCount = 1; // 0 = loops forever
[myAnimatedView startAnimating];
[self.view addSubview:myAnimatedView];
[myAnimatedView release];
}
-(void)turnPageBackward {
NSArray *myImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"PageTurnNine.png"],
[UIImage imageNamed:@"PageTurnEight.png"],
[UIImage imageNamed:@"PageTurnSeven.png"],
[UIImage imageNamed:@"PageTurnSix.png"],
[UIImage imageNamed:@"PageTurnFive.png"],
[UIImage imageNamed:@"PageTurnFour.png"],
[UIImage imageNamed:@"PageTurnThree.png"],
[UIImage imageNamed:@"PageTurnTwo.png"],
[UIImage imageNamed:@"PageTurnOne.png"],
nil];
UIImageView *myAnimatedView = [UIImageView alloc];
[myAnimatedView initWithFrame:CGRectMake(0, 0, 320, 480)];
myAnimatedView.animationImages = myImages;
myAnimatedView.animationDuration = .5; // seconds
myAnimatedView.animationRepeatCount = 1; // 0 = loops forever
[myAnimatedView startAnimating];
[self.view addSubview:myAnimatedView];
[myAnimatedView release];
}
答案 0 :(得分:1)
通常,当设备上的代码失败但模拟器失败时(反之亦然),罪魁祸首是为一个硬件而不是另一个硬件编译的库或其他编译源。
另一个相关的可能性是未正确添加资源,因此它不包含在设备的最终版本中。我会检查方法中的图像文件不起作用。
您还应该确认是否正在调用turnPageForward
。这将为您提供问题所在的线索。