我想将图像设置为UIScrollView,但是有一个问题。图像在UIScrollView之外

时间:2011-06-08 14:13:31

标签: iphone uiscrollview

我想将图像设置为UIScrollView,但是存在问题。图像在UIScrollView之外。 我使用[self.scrollView addSubview:view];

enter image description here

enter code here

scrollView = [[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 :(得分:1)

在将视图添加到滚动视图之前,是否要为视图指定所需的帧?