Your drawing code won't make much of a difference, I will assume you know how to draw what it is you want to draw. What is important here is setting up physics. If you have a physics engine running (like Chipmunk or others) then the effects of the shake to move the ball, which I'll get to in a second, may cause the ball to move in a different direction, if that's how you've written your physics. Keep this in mind. I'll assume for the moment that gravity is off.
The idea you want to do is first to figure out whether or not you're going to target iOS prior to version 3.2, because our gesture APIs are different between the two (one way works in 3.2 and later as well, but you really want to use gesture recognizers if you're not worried about supporting 3.0 or 3.1).
If you do want to support prior iOS versions than 3.2, then you'll want to look at the apis for motionEnded:withEvent: and motionBegan:withEvent: this will give you information about the motion of the device. Your final decision about whether or not it was a shake, and the details about the shake, should be done in motionEnded:withEvent: so you don't misfire. In here, you want to move the ball according to the information you get about the shake.
As for gesture recognizers, the same really holds true, though the APIs are so much easier. You simply create a shake gesture recognizer, and tell it what you want to do when it finds a shake. Real simple, but only available on iOS 3.2 and higher.