サブビューとして画像を含むスクロールビューがあります。背景が見えないように、スクロールビューの境界を画像ビューのサイズに設定したいと思います。
もうこんなことはしたくない。
奇妙な点は、画像をズームインまたはズームアウトした後、境界が自動的に修正されたように見え、邪魔にならないように画像を移動して背景を見ることができなくなることです。
これは私がコードのために行っていることです:
-(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;
上部のツールバーが画像で覆われていることを除いて、私が望むように機能します (背景は表示されません)。