我正在使用从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 =(