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)scal e 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)target Position {
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];
We can use below coding to zoom an image that inside UIScrollView
- (CGRect)zoomRectForScale:(
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER