2010-02-25 28 views
3

我有一個滾動視圖,其中我有一個imageview顯示960x960圖像,但它滾動到接近4倍的東西。我試圖記錄所有可能的視圖的寬度,並聲稱它是960x960(或更小,我認爲我記錄了屏幕寬度一次...?)iPhone SDK滾動查看顯示額​​外的空間

我需要此圖像以停止滾動在右下角圖像的角落,而不是進入死亡空間。任何幫助將不勝感激。

哎呀,甚至告訴我什麼對象的名稱是比我大scrollView.contentSize會把我在正確的軌道上......

//Test-Image is just a 960 by 960 image that's numbered around the edges 1-10 so you can tell if it's being moved 
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Test-Image.png"]]; 
self.imageView = tempImageView; 
[tempImageView release]; 

scrollView.contentSize = CGSizeMake(imageView.frame.size.width, imageView.frame.size.height); 

//Tested with this, results the same. 
//[scrollView setContentSize:CGSizeMake(960, 960)]; 

NSLog(@"What is my scrollView's height attribute?...%f", scrollView.contentSize.height); 
// Returns 960 
NSLog(@"What is in scrollView's width attribute?...%f", scrollView.contentSize.width); 
// Returns 960 

scrollView.contentOffset = CGPointMake(480, 480); 

scrollView.maximumZoomScale = 8.0; 
scrollView.minimumZoomScale = 0.25; 
// Commenting clipsToBounds out doesn't seem to have any effect 
scrollView.clipsToBounds = YES; 
scrollView.delegate = self; 

[scrollView addSubview:imageView]; 
+0

我想看看你是如何構建scrollview的內容。 – ISDi

回答

1

不幸的是,我沒有一個明確的答案。

  • 參考。嘗試[scrollView addSubview:self.imageView];而不是[... addSubview:imageView];

  • 內容大小。嘗試在添加ImageView後設置內容大小。
    [scrollView setContentSize:CGSizeMake(imageView.frame.size.width,imageView.frame.size.height)];

  • 代表。你是否使用並設置了scrollview的委託屬性(oIWScroll.delegate = self;)?

  • 剪切。這應該不重要。

  • ScrollView Frame。確保滾動視圖的框架等於或小於[UIScreen mainScreen] .applicationFrame。

  • 構築。當我遇到類似於你所描述的情況時,我所做的一件事就是創建一個容器UIView,將其添加到滾動視圖並將對象填充到容器視圖中。但你真的不應該爲一個圖像做這件事。
    我還設置了contentMode = UIViewContentModeTop。

我希望這些建議有幫助。