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];
agicfutureAsked:
Who is Participating?
 
pgnatyukConnect With a Mentor Commented:
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
                       fromRect:imageRect
                       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:
http://developer.apple.com/mac/library/documentation/cocoa/conceptual/CocoaDrawingGuide/Images/Images.html

You can make an image like here (if it is interesting for you):
http://www.cocoadev.com/index.pl?ThumbnailImages

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


0
 
agicfutureAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.