为什么我无法将 ZoomScale 设置为低于 1?
我正在使用从 PhotoScroller 示例 (WWDC10) 中提取的一些代码。但我使用的是 UIView 而不是 UIImageView。这是我所做的唯一更改(在 UIScrollView 子类上)。
我的问题是当我调用“configureForViewSize”时。它尝试应用 0.66 的 ZoomScale(以显示完整视图),但它不起作用。
设置 self.minimumZoomScale = minScale 后,我查看 self.zoomScale 的值,它始终等于 1
- (void)displayView:(UIView *)mView
{
// clear the previous view
[view removeFromSuperview];
[view release];
view = nil;
// reset our zoomScale to 1.0 before doing any further calculations
self.zoomScale = 1.0;
[self addSubview:mView];
[self configureForViewSize:mView.frame.size];
}
- (void)configureForViewSize:(CGSize)viewSize
{
CGSize boundsSize = [self bounds].size;
// set up our content size and min/max zoomscale
CGFloat xScale = boundsSize.width / viewSize.width; // the scale needed to perfectly fit the image width-wise
CGFloat yScale = boundsSize.height / viewSize.height; // the scale needed to perfectly fit the image height-wise
CGFloat minScale = MIN(xScale, yScale); // use minimum of these to allow the image to become fully visible
// on high resolution screens we have double the pixel density, so we will be seeing every pixel if we limit the
// maximum zoom scale to 0.5.
CGFloat maxScale = 1.0 / [[UIScreen mainScreen] scale];
// don't let minScale exceed maxScale. (If the view is smaller than the screen, we don't want to force it to be zoomed.)
if (minScale > maxScale) {
minScale = maxScale;
}
NSLog(@"contentSize %f %f", viewSize.width, viewSize.height);
NSLog(@"minScale %f", minScale);
NSLog(@"maxScale %f", maxScale);
self.contentSize = viewSize;
self.maximumZoomScale = maxScale;
self.minimumZoomScale = minScale;
//--> THIS IS NOT WORKING! =(
self.zoomScale = minScale; // start out with the content fully visible
NSLog(@"self.zoomScale %f", self.zoomScale);
}
控制台消息为:
2011-03-29 10:18:39.950 MyProj[6259:207] contentSize 1536.000000 893.000000
2011-03-29 10:18:39.953 MyProj[6259:207] minScale 0.666293
2011-03-29 10:18:39.954 MyProj[6259:207] maxScale 1.000000
2011-03-29 10:18:39.955 MyProj[6259:207] self.zoomScale 1.000000
编辑:
我自己想出来了。我忘记在“displayView”方法中分配 view = mView =(
I'm using some code extracted from PhotoScroller example (WWDC10). But I'm using an UIView instead of UIImageView. This is the only change I made (on the UIScrollView subclass).
My problem is when I call 'configureForViewSize'. It tries to apply a zoomScale of 0.66 (to show the full view), but it doesn't work.
After setting self.minimumZoomScale = minScale, then I look at the value of self.zoomScale and it's always equals to 1
- (void)displayView:(UIView *)mView
{
// clear the previous view
[view removeFromSuperview];
[view release];
view = nil;
// reset our zoomScale to 1.0 before doing any further calculations
self.zoomScale = 1.0;
[self addSubview:mView];
[self configureForViewSize:mView.frame.size];
}
- (void)configureForViewSize:(CGSize)viewSize
{
CGSize boundsSize = [self bounds].size;
// set up our content size and min/max zoomscale
CGFloat xScale = boundsSize.width / viewSize.width; // the scale needed to perfectly fit the image width-wise
CGFloat yScale = boundsSize.height / viewSize.height; // the scale needed to perfectly fit the image height-wise
CGFloat minScale = MIN(xScale, yScale); // use minimum of these to allow the image to become fully visible
// on high resolution screens we have double the pixel density, so we will be seeing every pixel if we limit the
// maximum zoom scale to 0.5.
CGFloat maxScale = 1.0 / [[UIScreen mainScreen] scale];
// don't let minScale exceed maxScale. (If the view is smaller than the screen, we don't want to force it to be zoomed.)
if (minScale > maxScale) {
minScale = maxScale;
}
NSLog(@"contentSize %f %f", viewSize.width, viewSize.height);
NSLog(@"minScale %f", minScale);
NSLog(@"maxScale %f", maxScale);
self.contentSize = viewSize;
self.maximumZoomScale = maxScale;
self.minimumZoomScale = minScale;
//--> THIS IS NOT WORKING! =(
self.zoomScale = minScale; // start out with the content fully visible
NSLog(@"self.zoomScale %f", self.zoomScale);
}
The console msgs are:
2011-03-29 10:18:39.950 MyProj[6259:207] contentSize 1536.000000 893.000000
2011-03-29 10:18:39.953 MyProj[6259:207] minScale 0.666293
2011-03-29 10:18:39.954 MyProj[6259:207] maxScale 1.000000
2011-03-29 10:18:39.955 MyProj[6259:207] self.zoomScale 1.000000
EDIT:
I figured it out by myself. I forgot to assign view = mView in "displayView" method =(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论