私はしばらくの間、この機能に取り組んできました。私はウェブの周りを見てきましたが、何の答えも見つからないようです。私は2つのUIScrollviewsを持つビューを持っています。それ自体にUIImageViewがそれぞれ含まれています。だから私は別々にスクロール/ズーム可能な私のビュー上の画像にすることができます。私は2つのズーム可能なUIImageViewsを持っていたいと思っています...同じビューでは動作しません!
これはかなりシンプルなようですが、うまく動作しません。私はIBでScrollView/ImageViewのペアをセットアップしてOKにしました。今私のviewDidLoadコードは次のようになります。
-(void) viewDidLoad
{
// set the image to be displayed, pic your own image here
imageView = [[MyImage alloc] initWithImage: [UIImage imageNamed: @"newBackground.png"]];
// yes we want to allow user interaction
[imageView setUserInteractionEnabled:YES];
// set the instance of our myScrollView to use the main screen
scrollView = [[MyScroll alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
// turn on scrolling
[scrollView setScrollEnabled: YES];
// set the content size to the size of the image
[scrollView setContentSize: imageView.image.size];
// add the instance of our myImageView class to the content view
[scrollView addSubview: imageView];
// flush the item
[imageView release];
// set max zoom to what suits you
[scrollView setMaximumZoomScale:1.0f];
// set min zoom to what suits you
[scrollView setMinimumZoomScale:0.25f];
// set the delegate
[scrollView setDelegate: self];
// scroll a portion of image into view (my image is very big) :)
//[scrollView scrollRectToVisible:CGRectMake(100, 100, 320, 440) animated:NO];
// yes to autoresize
scrollView.autoresizesSubviews = YES;
// set the mask
scrollView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
// set the view
//self.view =scrollView;
[scrollView setFrame:CGRectMake(0, 0, 320, 240)];
self.view =scrollView;
imageView1 = [[MyImage alloc] initWithImage: [UIImage imageNamed: @"newBackground.png"]];
// yes we want to allow user interaction
[imageView1 setUserInteractionEnabled:YES];
// set the instance of our myScrollView to use the main screen
scrollView1 = [[MyScroll alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
// turn on scrolling
[scrollView1 setScrollEnabled: YES];
// set the content size to the size of the image
[scrollView1 setContentSize: imageView1.image.size];
// add the instance of our myImageView class to the content view
[scrollView1 addSubview: imageView1];
// flush the item
[imageView1 release];
// set max zoom to what suits you
[scrollView1 setMaximumZoomScale:1.0f];
// set min zoom to what suits you
[scrollView1 setMinimumZoomScale:0.25f];
// set the delegate
[scrollView1 setDelegate: self];
// scroll a portion of image into view (my image is very big) :)
//[scrollView scrollRectToVisible:CGRectMake(100, 100, 320, 440) animated:NO];
// yes to autoresize
scrollView1.autoresizesSubviews = YES;
// set the mask
scrollView1.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
// set the view
//self.view =scrollView;
[scrollView1 setFrame:CGRectMake(0, 300, 320, 220)];
//I do this only because I don't know what else to do. This effectively adds the scrollview to the scrollview...
self.view =scrollView1;
そして、最初のscrollView負荷が、その後二つが1つにネストされています!私は[self.view addSubView:scrollView1];
をやってみたが、それはちょうどアプリをクラッシュさせた。私は本当に掘り下げてscrollViewsを最大限に引き出すために最善を尽くしていますが、ここでは所有しています。
助けてください!
おかげ
**さらに明確にするためには、私が望むすべてはパンとその中の画像をズームすることができ、画像の上半分にscrollViewを持つことですし、別のscrollViewがfirtから分離しますそれはパンと最初の独立した画面の下半分、上でズームすることができます**
お返事ありがとうございました。適切な場所に適切なコンテンツを表示するために、両方のscrollViewを取得しました。しかし、今ではズームに問題があります。私が最初のscrollViewの内部を挟むと、最初の画像がズームアップします。 2番目のscrollViewの内部を挟むと、最初の画像がズームされます。そして、2番目のscrollViewは大きくなります...イメージのサイズが増えているようですが、それは...どんなアイデアでもありませんか? –