我有一个图像作为子视图的滚动视图。我想将scrollview的边界设置为图像视图的大小,以便您无法看到任何背景。设置视图边界
我不希望这种情况发生了。
奇怪的是,在你放大或缩小图像后,边界似乎会自行修复,而且你不能再移动图像并看到背景。
这就是我要去下面的代码:
-(UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView
{
// return which subview we want to zoom
return self.imageView;
}
-(void)viewDidLoad{
[super viewDidLoad];
[self sendLogMessage:@"Second View Controller Loaded"];
//sets the initial view to scale to fit the screen
self.imageView.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds));
//sets the content size to be the size our our whole frame
self.scrollView.contentSize = self.imageView.image.size;
//setes the scrollview's delegate to itself
self.scrollView.delegate = self;
//sets the maximum zoom to 2.0, meaning that the picture can only become a maximum of twice as big
[self.scrollView setMaximumZoomScale : 2.5];
//sets the minimum zoom to 1.0 so that the scrollview can never be smaller than the image (no matter how far in/out we're zoomed)
[self.scrollView setMinimumZoomScale : 1.0];
[imageView addSubview:button];
}
我认为,这条线将解决我的问题
//sets the content size to be the size our our whole frame
self.scrollView.contentSize = self.imageView.image.size;
但就像我说的,这只是在我放大或缩小的作品。
编辑:当我切换
self.scrollView.contentSize = self.imageView.image.size;
到
self.scrollView.frame = self.imageView.frame;
它就像我希望它(你看不到的背景),在工具栏上除顶部被图像覆盖。