How can I get the current zoom level in a UIScrollView?

醉酒当歌 提交于 2019-12-09 16:30:54

问题


In an attempt to create a workaround for centering an image in a UIScrollView and make it behave as Apple's Photos app does, I need to get the current zoom level and use the number to calculate the amount the image should be inset at each zoom level.

(Note: I am aware that some programmers are centering an image in a scrollview by centering the image in a UIView that is the same size as the scrollview. This does not give good results and I am trying to find out how apple made it work in the photos app.)

So, anyone know how to get the current zoom level of the content in a UIScrollView?


回答1:


In OS 3.x, there's a property called "zoomScale" that will give you what you want. In 2.x, I believe you can look directly at the contentView's transform to obtain this (but that is, of course, not 'official'.)




回答2:


Yep I got your problem's answer. I think you should use this method in your scrollViewController Class.

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale{
    NSLog(@"Zoomscale %f",scale);
        NSLog(@"Zoom End!");
}


来源:https://stackoverflow.com/questions/1451071/how-can-i-get-the-current-zoom-level-in-a-uiscrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!