iPhone 发布版本的功能与调试版本不同

发布于 2024-08-03 00:10:08 字数 1532 浏览 5 评论 0原文

当使用调试版本时,我的程序在 iPhone 模拟器和 iPhone 本身上都按照我希望的方式运行。然而,当我将其更改为发布版本时,它可以在 iPhone 模拟器上运行,但不能在设备上运行。我正在尝试用计时器在屏幕上制作一个球的动画,如果球与屏幕边缘碰撞,球应该从侧面弹开。这对于调试版本来说效果很好,但发布版本仅适用于模拟器而不是设备。在发布版本中,球甚至不会在设备上移动。

我有一种感觉,这与从调试切换到发布版本时更改的优化级别有关。如果这是真的,我该如何更改我的代码以更好地适应优化级别?

使用 initWithNibName: 调用视图控制器,其中包含:

CGRect ballRect = CGRectMake(133, 424, 55, 56); 
newBall = [[Ball alloc] initWithFrame: ballRect];
[self.view addSubview: newBall];
[self setImage: [UIImage imageNamed: @"Red.png"]];

Ball *newBall 在接口文件中声明。球在屏幕上正确显示,所有构建上的图像均正确。

当用户点击屏幕时,会调用移动球的计时器:

-(void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event{
    touch = [touches anyObject];
    touchPoint = [touch locationInView: self.view];
    dx = touchPoint.x - newBall.center.x;
    dy = touchPoint.y - newBall.center.y;
    newBallTimer = [NSTimer scheduledTimerWithTimeInterval: 1.0/50.0 target: self selector: @selector(moveBall) userInfo: nil repeats: YES];
}

CGPoint touchPoint、UITouch *touch、float dx、float dy 和 NSTimer *newBallTimer 也在接口文件中声明。

这是我用于移动球和检测碰撞的代码:

-(void) moveBall
{       
    newBall.center = CGPointMake( newBall.center.x + dx, newBall.center.y + dy );

    // left boundary
    if( newBall.frame.origin.x <= 20 )
    {
        dx = abs(dx);
    }   
    else if( newBall.center.x >= 280 )  
    {
        dx = -abs(dx);
    }
}       

在设备上的发布版本中,球不会移动。相反,它似乎被发送到屏幕底部并停留在那里。

任何建议/解决方案/想法都将受到高度赞赏。 提前致谢!

My program works the way I want it to on both the iPhone simulator and the iPhone itself when using the debug build. However when I change it to the release build, its works on the iPhone simulator but not on the device. I'm trying to animate a ball across the screen with a timer and the ball should bounce off the sides if it collides with the edges of the screen. This works fine for the debug builds but the release build only works on the simulator and not the device. The ball does not even move on the device with the release build.

I have a feeling this has to do with the optimization level that is changed when switched from a debug to a release build. If this is true how can I change my code to better suit the optimization level?

The view controller is called with initWithNibName: which contains:

CGRect ballRect = CGRectMake(133, 424, 55, 56); 
newBall = [[Ball alloc] initWithFrame: ballRect];
[self.view addSubview: newBall];
[self setImage: [UIImage imageNamed: @"Red.png"]];

Ball *newBall was declared in the interface file. The ball is shown correctly on the screen with the correct image on all builds.

The timer to move the ball is called when the user taps the screen:

-(void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event{
    touch = [touches anyObject];
    touchPoint = [touch locationInView: self.view];
    dx = touchPoint.x - newBall.center.x;
    dy = touchPoint.y - newBall.center.y;
    newBallTimer = [NSTimer scheduledTimerWithTimeInterval: 1.0/50.0 target: self selector: @selector(moveBall) userInfo: nil repeats: YES];
}

CGPoint touchPoint, UITouch *touch, float dx, float dy and NSTimer *newBallTimer were declared in the interface file too.

Here is my code for moving the ball and detecting collisions:

-(void) moveBall
{       
    newBall.center = CGPointMake( newBall.center.x + dx, newBall.center.y + dy );

    // left boundary
    if( newBall.frame.origin.x <= 20 )
    {
        dx = abs(dx);
    }   
    else if( newBall.center.x >= 280 )  
    {
        dx = -abs(dx);
    }
}       

On the release build on the device the ball doesn't move. Instead it seems to be sent to the bottom of the screen and stay there.

Any suggestions/solutions/ideas are highly appreciated.
Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凌乱心跳 2024-08-10 00:10:08

您如何将版本构建到您的设备上?或者您的意思是临时构建?

无论哪种情况,您是否有任何#define 或#ifdef 代码块在您进行发布构建时可能被注释掉?

另一种可能性是在 NSAssert 中执行实际逻辑,然后在发布版本中关闭断言。当您关闭断言时,该断言中的任何代码都不会被调用。

How are you getting the release build onto your device? Or do you mean an Ad Hoc build?

In either case, do you have any #define or #ifdef code blocks that are perhaps being commented out when you do the release build?

Another possibility is doing actual logic in a NSAssert and then turning off asserts in the release build. When you turn off asserts any code in that assert will not be called.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文