我有一個圖像作爲子視圖的滾動視圖。我想將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;
它就像我希望它(你看不到的背景),在工具欄上除頂部被圖像覆蓋。