19

I have an app which in xcode 4.5 and ios 6.1 worked perfectly fine when scrolling. However, after downloading xcode 5 and iOS 7 my scroll views does not work anymore.???

Here is my .h file:

#import <UIKit/UIKit.h>

@interface GrillretterViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIScrollView *grillretterScroller;
@property (assign) CGPoint rememberContentOffset;

@end

And here is my .m file:

#import "GrillretterViewController.h"

@interface GrillretterViewController ()

@end

@implementation GrillretterViewController
@synthesize grillretterScroller, rememberContentOffset;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [grillretterScroller setScrollEnabled:YES];

    // Do any additional setup after loading the view.
}

- (void) viewDidAppear:(BOOL)animated {
    [grillretterScroller setContentSize:CGSizeMake(300, 915)];

}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];
    self.grillretterScroller.contentOffset = CGPointMake(0, 0);
}

- (void)viewWillDisappear:(BOOL)animated {
    self.rememberContentOffset = self.grillretterScroller.contentOffset;
    [super viewWillDisappear:animated];
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    self.grillretterScroller.contentOffset = CGPointMake(0, self.rememberContentOffset.y);
}



- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

PLEASE help! I'm stuck!

Best regards!

Tobias Lindgreen
  • 297
  • 1
  • 4
  • 11

9 Answers9

50

I solved this by deselecting 'Use Autolayout' in the File Inspector pane of main view within the Scroll View.

enter image description hereenter image description here

If you want to keep 'Autolayout' enabled, try 'Editor -> Reslove Autolayout Issues -> Add Missing Constraints'. The key constraint appears to be 'Bottom Space to: Superview and in my case was -300, giving 300 scroll space on the botton of the view.

Jim Holland
  • 1,180
  • 12
  • 19
  • this worked for me too.... I'm pretty sure your answer should be marked as 'correct' – Mr.Hardy Sep 22 '13 at 03:45
  • 12
    You'd lose all the benefits of AutoLayout in every viewcontroller in your storyboard. I doubt this is an option for most people. – Phil Sep 22 '13 at 06:14
  • This worked! However, the autolayout is then disabled for all viewcontrollers, which created some different problems. But solved the question. :) Thanks – Tobias Lindgreen Sep 23 '13 at 08:34
  • 9
    This is not the right solution to disable autolayout feature. – Satyam Sep 25 '13 at 04:22
  • Satyam svv, perhaps you post your 'correct' solution? The above was my way of making it work, which may not be ideal for all! – Jim Holland Sep 26 '13 at 07:02
  • 'Resolve autolayout issues' nearly worked for me. In addition to this my view within scroll view set the vertical constraint to -167 after doing this, editing this to 0 then got the scrolling working for me. – Adam Knights Nov 21 '13 at 17:26
  • Maan! Loved the Resolve Autolayout Issues! Worked like a charm! – Thpramos Apr 10 '14 at 21:33
  • You are awesome, I'am so glad I decided to search the answer instead of spending one more day trying to figure out the issue! – Javier Giovannini Jun 15 '14 at 16:18
28

As mentioned by user2394787:

Select your view controller that has the scrollview then go to

Editor -> Resolve AutoLayout Issues -> Add Missing Contraints in [your view controller].  

This will make it work.

I tried to vote up the above answer but do not have enough rep.

Darwind
  • 7,284
  • 3
  • 49
  • 48
jcksu3
  • 281
  • 2
  • 3
  • THIS IS THE ANSWER PEOPLE!!!! It works in IOS7/XCODE5 - Ill say it again. To create a working scrollview with no code using storyboards follow the directions given via the accepted answer on this thread: http://stackoverflow.com/questions/8809984/designing-inside-a-scrollview-in-xcode-4-2-with-storyboards and then do the editor-> resolve autolayout issues -> add missing contraints and it will work. – ChuckKelly Dec 04 '13 at 00:21
7

I just solved it by going to Editor > Resolve AutoLayout Issues > Add Missing Constraints in View Controller

Hope this helps.

diogo.appDev
  • 1,595
  • 5
  • 16
  • 30
6

I just set "Vertical Space" to auto constant value. May be it help in some case.

Click the "Vertical Space"

and set it in Attributes inspector

tick that Standard

I hope it help. Thx.

Pokotuz
  • 121
  • 1
  • 5
2

I'm not sure if this is going to work

- (void) viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [grillretterScroller setContentSize:CGSizeMake(self.view.bounds.size.width, 915)];
}
Camo
  • 1,778
  • 14
  • 12
2
- (void)viewDidLayoutSubviews {
    [self performSelector:@selector(updateContentSize)
               withObject:nil
               afterDelay:0.25];

}

-(void)updateContentSize{
    UIView *viewLast = [viewContent viewWithTag:100];
    scrollViewAd.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, CGRectGetMaxY(viewLast.frame));
}
pkc456
  • 8,350
  • 38
  • 53
  • 109
0

I didn't have a fixed height so I set the contentsize of the scrollview in code according to my label inside the scrollview

CGSize scrollViewContentSize = CGSizeMake(320, myLabel.frame.size.height);
[self.scrollView setContentSize:scrollViewContentSize];
Priebe
  • 4,942
  • 3
  • 24
  • 38
0

With AutoLayout enabled, make sure Vertical Spacing (@"V:|-[subview]-|") is applied between the UIScrollView and its subview. If your scrollView is for horizontal scrolling, apply Horizontal Spacing (@"H:|-[subview]-|").

MkVal
  • 1,044
  • 1
  • 11
  • 17
0

I had the same issue after developing an app for iOS8, then testing on iOS7 afterwards. Although I had tried setting certain options on the scroll view such as:

[self.scrollView setScrollEnabled:YES];
[self.scrollView setContentSize:CGSizeMake(self.view.frame.size.width, 700)];
[self.scrollView setContentOffset:CGPointZero];

The solution that worked for me was to go into the storyboard file, and ensure that you have constraints set for all views within the scroll view. The scroll view's content size is calculated by the constraints of each subview within the scroll view, so in my case, I had a UIView and UITableView. After setting constraints for UIView (top, leading, trailing, height), and UITableView (vertical spacing to UIView, leading, trailing, bottom), the scroll view calculated the content size and started to function.

While turning off Auto Layout does work, it's not an ideal solution for everyone. Just play around with Storyboard and set constraints for all subviews in the scroll view, so that a vertical line of constraints are set, from the top of the scroll view to the bottom.

Andy Shephard
  • 1,726
  • 17
  • 26