0

サブビューとして画像を含むスクロールビューがあります。背景が見えないように、スクロールビューの境界を画像ビューのサイズに設定したいと思います。

ここに画像の説明を入力

もうこんなことはしたくない。

奇妙な点は、画像をズームインまたはズームアウトした後、境界が自動的に修正されたように見え、邪魔にならないように画像を移動して背景を見ることができなくなることです。

これは私がコードのために行っていることです:

-(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;

上部のツールバーが画像で覆われていることを除いて、私が望むように機能します (背景は表示されません)。

4

2 に答える 2

1

imageView.image.size は必ずしも imageView 自体のフレームではありません。 scrollview.frame = imageView.frame

その後

scrollView.contentSize = imageView.image.size

その後、境界線は表示されません。画像を最初から最大サイズにしたい場合は、

imageView.frame = image.size;

[imageView setImage:image];

scrollView.frame = self.view.frame; //or desired size

[scrollView addSubView:imageView];

[scrollView setContentSize:image.size]; //or imageView.frame.size

于 2012-07-12T18:25:27.450 に答える
0

これを修正するために、新しい を宣言し、CGRectその原点を scrollView の原点に設定し、そのサイズをビューの境界に設定してから、この CGRect を scrollview フレームに割り当て直しました。

CGRect scrollFrame;
scrollFrame.origin = self.scrollView.frame.origin;
scrollFrame.size = CGSizeMake(CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds));
self.scrollView.frame = scrollFrame; 
于 2012-07-13T14:57:14.380 に答える