When I make and setup a scrollView in Xcode, It never works. It simply wont scroll and show my content! I have coded the backend of it but no go! I have been using this tutorial since iOS 4: Devx Scrollview Tutorial
Now, I think it is broken in iOS 6 due to the new screen size on the new iPhone. Here is the backend code I have been using:
scrollView.frame = CGRectMake(0, 0, 320, 520);
//---set the content size of the scroll view---
[scrollView setContentSize:CGSizeMake(320, 520)];
// Do any additional setup after loading the view.
The scrollview sizes in Xcode are Width: 320, Height: 520.
What am I doing wrong? It is probably something stupid.
Update:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.overlay removeFromSuperview];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(keyboardWillShow:) name:
UIKeyboardWillShowNotification object:nil];
[nc addObserver:self selector:@selector(keyboardWillHide:) name:
UIKeyboardWillHideNotification object:nil];
tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(didTapAnywhere:)];
[self customizeAppearance];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"stone.png"]];
[scrollView setScrollEnabled:YES];
scrollView.frame = ([UIScreen mainScreen].bounds);
//---set the content size of the scroll view---
[scrollView setContentSize:CGSizeMake(320, 800)];
// Do any additional setup after loading the view.
}
You set the frame size and content size to be the same. Where do you expect the scroll view to scroll to? You should set the
UIScrollView‘sframeto be where you want the viewport to be on the screen (probably[UIScreen mainScreen].bounds), and thecontentSizeto be the total area you want the scroll to reach, it sounds like you want this to be 320×520.I’ve written a simple example program. I created a new “single view” project and just put this in the
viewDidLoadmethod of the main VC: