xcode - move UIImage that inside UIScrollView base on Apple sample code [ScrollViewSuite]

Base on the [Apple Developer Sample code: ScrollViewSuite - 2_Autoscroll]

We can use below coding to zoom an image that inside UIScrollView

- (CGRect)zoomRectForScale:(float)scale withCenter:(CGPoint)center {
    CGRect zoomRect;

    zoomRect.size.height = [imageScrollView frame].size.height / scale;
    zoomRect.size.width  = [imageScrollView frame].size.width  / scale;

    zoomRect.origin.x    = center.x - (zoomRect.size.width  / 2.0);
    zoomRect.origin.y    = center.y - (zoomRect.size.height / 2.0);
    return zoomRect;

CGRect zoomRect = [self zoomRectForScale:newScale withCenter:tapPoint];
[imageScrollView zoomToRect:zoomRect animated:YES];

If i only want to move the image when i press some button. Can i simply write iit as below?

- (CGRect)moveMyImage:(float)scale withCenter:(CGPoint)targetPosition {
    CGRect zoomRect;

    zoomRect.size.height = [imageScrollView frame].size.height;
    zoomRect.size.width  = [imageScrollView frame].size.width;

    zoomRect.origin.x    = targetPosition.x;
    zoomRect.origin.y    = targetPosition.y;
    return zoomRect;

CGRect zoomRect = [self moveMyImage:newScale withCenter:tapPoint];
[imageScrollView zoomToRect:zoomRect animated:YES];
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Seems like you need to add:
[self setNeedsDisplay:YES];

That's what I can say from what I see in this code.
I guess you draw somewhere this image (in - (void)drawRect:(NSRect)dirtyRect) like here:

if (image)
      NSRect imageRect;
      imageRect.origin = NSZeroPoint;
      imageRect.size = [image size];
      NSRect drawingRect = [self currentRect];
      [image drawInRect:drawingRect
                       operation:NSCompositeSourceOver fraction:opacity];

Actually you can scale the image itself these two rectangles in the code above (drawInRect, fromRect).

Here you can look for a section about the drawing an image on the view:

You can make an image like here (if it is interesting for you):

More about UIImage: http://blog.logichigh.com/2008/06/05/uiimage-fix/


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
agicfutureAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.