I want to set image into UIScrollView, but there is a problem. Image is outside of UIScrollView
I want to set image into UIScrollView, but there is a problem. Image is outside of UIScrollView. I use [self.scrollView addSubview:view];
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 *)vie开发者_如何学运维w == [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
I've attached my project at my project
Are you assigning desired frame to the view before adding it to the scroll view?
精彩评论