0
我想将图像设置为UIScrollView,但存在问题。图像不在UIScrollView中。 我使用[self.scrollView addSubview:view];我想设置图像到UIScrollView,但有一个问题。图像不在UIScrollView
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
您可以在我的照片上看到UIScrollView。它在Balmer的照片后面并且有灰色。 – Voloda2 2011-06-08 14:22:53
我下载了你的项目。问题是您的图像高度为280,但滚动视图高度非常低。请在xib中将滚动视图高度设置为等于或高于图像的最高高度,并且它将起作用。如果您有任何问题,我会上传更正的项目。更具体地说,滚动视图高度大约为119,其内容大小高度为320.因此,您只能看到滚动视图框架(高度119 px)的灰色区域,但它试图显示280像素高度的图像这超出了灰色地带。 – 2011-06-08 14:29:38
我将scrollView.clipsToBounds从NO更改为YES。它帮助了我。 – Voloda2 2011-06-08 15:27:46