This looks like the example from the aPress bbok: introduction to iPhone gaming.
Basically, you need to calculate the position of the ball and if it's x value is less than say 5 and greater than 300 (just example #'s) reverse it's x direction. Same thing for the Y value. It's very similiar to making the ball "bounce" off the paddle.
This code goes inside the gameLogic or animateBall method called by the timer.
Code:
if (ball.center.x > 310 || ball.center.x < 16)
ballMovement.x = -ballMovement.x;
if (ball.center.y < 32)
ballMovement.y = -ballMovement.y;
if (ball.center.y > 444) {
[self pauseGame];
isPlaying = NO;
lives--;
livesLabel.text = [NSString stringWithFormat:@"%d", lives];
if (!lives) {
[self saveGameState];
messageLabel.text = @"Game Over";
} else {
messageLabel.text = @"Ball Out of Bounds";
}
messageLabel.hidden = NO;
}
The source code is available for free @
APRESS.COM: Beginning iPhone Games Development