开发者

UIScrollView setContentOffset with Scale

开发者 https://www.devze.com 2023-02-15 04:00 出处:网络
How do I scroll to x,y with a scale not to 1.0? I thought all I had to do is multiple it by the scale.if Iscroll to 100,100 when th开发者_运维百科e zoomScale is 1, should this be converted to 50,50 w

How do I scroll to x,y with a scale not to 1.0?

I thought all I had to do is multiple it by the scale. if I scroll to 100,100 when th开发者_运维百科e zoomScale is 1, should this be converted to 50,50 when the zoomScale is .50?


Not sure about setContentOffset but no conversion is necessary if you do it like this:

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return self.rootView;
}

- (void)zoomToPointInRootView:(CGPoint)center atScale:(float)scale {
    CGRect zoomRect;

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

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

    [scrollView zoomToRect:zoomRect animated:NO];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消