Link to home
Start Free TrialLog in
Avatar of agicfuture
agicfuture

asked on

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];
ASKER CERTIFIED SOLUTION
Avatar of pgnatyuk
pgnatyuk
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of agicfuture
agicfuture

ASKER

Thanks