Tobias Lindgreen
Tobias Lindgreen

Reputation: 297

UIScrollView doesn't scroll after upgrading to iOS7 / xcode 5

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!

Upvotes: 19

Views: 27959

Answers (9)

pkc
pkc

Reputation: 8516

- (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));
}

Upvotes: 2

Andy Shephard
Andy Shephard

Reputation: 1904

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.

Upvotes: 0

MkVal
MkVal

Reputation: 1064

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]-|").

Upvotes: 0

Priebe
Priebe

Reputation: 4992

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];

Upvotes: 0

Pokotuz
Pokotuz

Reputation: 121

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.

Upvotes: 6

Jim Holland
Jim Holland

Reputation: 1225

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.

Upvotes: 50

jcksu3
jcksu3

Reputation: 281

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.

Upvotes: 28

diogo.
diogo.

Reputation: 1113

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

Hope this helps.

Upvotes: 7

Camo
Camo

Reputation: 1778

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)];
}

Upvotes: 2

Related Questions