I believe your code above should work fine. setContentSize will prevent the contentOffset from getting larger. You may have to start, though, by setting contentOffset yourself (once) if the user has already scrolled outside that area. (Try resetting it to (0, 0), for example.)
Also, are you permitting zooming? If you have a zoom != 1, the content size may not be what you think it is. Try setting zoom to 1 before modifying the content size.