2011-06-08 65 views
0

我想將圖像設置爲UIScrollView,但存在問題。圖像不在UIScrollView中。 我使用[self.scrollView addSubview:view];我想設置圖像到UIScrollView,但有一個問題。圖像不在UIScrollView

enter image description here

enter code here 

滾動視圖= [[UIScrollView中的alloc] initWithFrame:方法scrollViewRect];

-(void)scrollViewDidScroll:(UIScrollView *)sv 
{ 
    int page = [self currentPage]; 
    // Load the visible and neighbouring pages 
    [self loadPage:page-1]; 
    [self loadPage:page]; 
    [self loadPage:page+1]; 
} 


-(void)loadPage:(int)page 
{ 
// Sanity checks 
if (page < 0) return; 
if (page >= [scrollViewPages count]) return; 

// Check if the page is already loaded 
UIView *view = [scrollViewPages objectAtIndex:page]; 

// if the view is null we request the view from our delegate 
if ((NSNull *)view == [NSNull null]) 
{ 
    view = [delegate viewForItemAtIndex:self index:page]; 
    [scrollViewPages replaceObjectAtIndex:page withObject:view]; 
} 

// add the controller's view to the scroll view if it's not already added 
if (view.superview == nil) 
{ 
    // Position the view in our scrollview 
    CGRect viewFrame = view.frame; 
    viewFrame.origin.x = viewFrame.size.width * page; 
    viewFrame.origin.y = 0; 

    view.frame = viewFrame; 

    [self.scrollView addSubview:view]; 
} 

}

enter code here 

我已經附上了我的項目在my project

回答

1

你分配所需的幀的視圖將其添加到滾動視圖之前?

+0

您可以在我的照片上看到UIScrollView。它在Balmer的照片後面並且有灰色。 – Voloda2 2011-06-08 14:22:53

+0

我下載了你的項目。問題是您的圖像高度爲280,但滾動視圖高度非常低。請在xib中將滾動視圖高度設置爲等於或高於圖像的最高高度,並且它將起作用。如果您有任何問題,我會上傳更正的項目。更具體地說,滾動視圖高度大約爲119,其內容大小高度爲320.因此,您只能看到滾動視圖框架(高度119 px)的灰色區域,但它試圖顯示280像素高度的圖像這超出了灰色地帶。 – 2011-06-08 14:29:38

+0

我將scrollView.clipsToBounds從NO更改爲YES。它幫助了我。 – Voloda2 2011-06-08 15:27:46