0

I have looked around many different threads over the same issue and can't seem to grasp what is going on here. I created a very basic and simple project. What I want to happen is for a bunch of elements to be inside of a scroll view that scrolls properly. These elements may include a UITableView that scrolls independently (or not). Here is how I set up my basic project:

IB View

Running this in the simulator will result in a view that doesn't scroll. This is expected as there is more than enough room for all of the elements. I then changed the size of UIScrollView like so:

IB View 2

Running this in the simulator results in a smaller view that will not scroll. I assume I am not doing this the correct way. Here is the code I have most recently tried:

ViewController.h

@interface ViewController : UIViewController <UIScrollViewDelegate> @property (strong, nonatomic) IBOutlet UIScrollView *scrollView; @property (strong, nonatomic) IBOutlet UIButton *buttonOne; @property (strong, nonatomic) IBOutlet UIButton *buttonTwo; @property (strong, nonatomic) IBOutlet UIButton *buttonThree; @property (strong, nonatomic) IBOutlet UIButton *buttonFour; @end 

ViewController.m

#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [self.buttonOne setTranslatesAutoresizingMaskIntoConstraints:NO]; [self.buttonTwo setTranslatesAutoresizingMaskIntoConstraints:NO]; [self.buttonThree setTranslatesAutoresizingMaskIntoConstraints:NO]; [self.buttonFour setTranslatesAutoresizingMaskIntoConstraints:NO]; [self.scrollView setTranslatesAutoresizingMaskIntoConstraints:NO]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end 

Any help would be greatly appreciated.

1 Answer 1

3

The problem is that when you change the size of the scroll view in interface builder, you are also setting the content's size to the same as the frame size.

You can manually increase the content size of the scroll view in code so that you can scroll it like this:

// scrollView is an outlet to your scroll view // Add 200 points to the bottom of the scroll view [self.scrollView setContentInset:UIEdgeInsetsMake(0, 0, 200, 0)]; 

Though, you probably don't need to do this as long as you draw the sub view at full size, and make it a sub view of some other view, and let it automatically re-size itself.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I put all of my UI elements (buttons, tables) in a UIView which is a subview of a UIScrollView. Everything works great without any additional code.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.