1

2ND UPDATE

Courtesy of this thread
In iOS6, XCode 4.5, UIScrollView is not Scrolling, despite contentSize being set

the answer has been provided! Turning off Auto Layout on your Storyboard (the entire thing) will fix ScrollView and allow things to scroll properly. Spread the word people!

UPDATE Added code. Seriously cannot figure out why this will not work on a iPad.

.h file

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;

@end

.m file

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
self.scrollView.contentSize = CGSize(768, 1600);
}

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

@end

Again just to clarify I'm using Storyboards, I'm first dragging in a ScrollView, setting the size to standard iPad screen (768x1004 because I have a Nav bar at the top) then adding my image on top of that and setting it's size (768x1600). Then I connect both of these to the header file (as shown above) and still I can't get the image to scroll. I have my view mode set to "Aspect Fit", could this be the issue? I've tried other settings and no luck but not all of them.

Any specific advice would be so appreciated!

ORIGINAL POST

I know there a number of topics out there regarding this one, but I'm having a dog of a time trying to get a ScrollView to work. I am attempting to load an image that is 768x1600 (on an iPad screen only) so that you have to vertically scroll to see more of the image's content. To create the ScrollView, I use a Storyboard and drag a ScrollView into the ViewController frame, align it and ensure interactions are enabled. Then, on top of the ScrollView (also in Storyboard) I add the UIImage I wish to use (ensuring it is a subview) and size it accordingly, then set interactions enabled as well.

No matter how hard I try, I cannot get this to work in Simulator or on my device. I have made sure that my ScrollView is set as a delegate in the IB, that is has an IBOutlet on the header file and is both synthesized and loaded into my implementation file. I have also ensured that I have set contentSize by;

self.scrollView.contentSize = CGSizeMake(768, 1600);

I have also tried to add the UIImage as a Subview via code (as opposed to on the Storyboard) and when I do this the image does not appear when I run Simulator. On top of this, when I click the page no scrolling option is available.

Any help anyone can give me on this one is much appreciated. If code is necessary I will post it.

Community
  • 1
  • 1
Slider257
  • 69
  • 1
  • 12
  • read the tutorials http://stackoverflow.com/questions/820557/are-there-any-good-uiscrollview-tutorials-on-the-net – Rachel Gallen May 09 '13 at 19:12
  • http://idevzilla.com/2010/09/16/uiscrollview-a-really-simple-tutorial/ – Rachel Gallen May 09 '13 at 19:13
  • http://www.edumobile.org/iphone/ipad-development/a-simple-scroll-view-in-ipad-programming/ – Rachel Gallen May 09 '13 at 19:15
  • Thanks Rachel for these links. Seeing that these are like others that I have found has helped me to be more specific in my question. I will edit and see if that can help shed some light on my dilemma. – Slider257 May 09 '13 at 19:45
  • The issues with these, as well as all the tutorials I've found is that they are far too out-of-date. Xcode is much different than when most of these tutorials were written (as witnessed by storyboards being used when only XIB's existed and the fact that you don't need to synthesize objects anymore yet all the older tutorials call for it) so I find that every time I attempt to implement these tutorials, they fail to work as well. Does anyone know of a current (iOS 6 or higher) tutorial specific for the iPad (as almost all of these are for iPhone)? – Slider257 May 09 '13 at 21:43
  • You are setting the `frame` somewhere, right? – Undo May 10 '13 at 04:02

1 Answers1

2

I think I just figured it out. You say you drug the UIImageView on top of the scroll view.

UIImageView's aren't user-interactable!

Try selecting your image view in Interface Builder and setting 'User interaction enabled' to YES for the image view.

If that doesn't work, I would suggest adding the image view in code (remove it from IB first):

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"someImage.png"]];
    self.imageView.frame = CGRectMake(0,0,768,1600);
    self.imageView.userInteractionEnable = YES;
    [self.scrollView addSubview:self.imageView];
    self.scrollView.contentSize = CGSizeMake(768, 1600);
    self.scrollView.frame = self.view.bounds;
}

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

@end
Undo
  • 25,519
  • 37
  • 106
  • 129
  • Thanks a bunch! I will indeed try your solution. I did ensure that User Interactions were enabled on the UIImageView so I know it's not that. Also after dragging in the ImageView on top of the ScrollView, I then embedded the ImageView inside the ScrollView (Editor > Embed In > ScrollView). I'll still try it in code in a bit and get back to you. – Slider257 May 10 '13 at 16:02
  • Okay, finally got a chance to try the code. Sadly it produced a number of errors. I needed to change CGSize to CGSizeMake in the self.scrollView.contentSize. I also needed to change userInteractionEnable to userInteractionEnabled. Sadly I can't the last issue, which has to do with the first self.imageView section right under View Did Load. When I put the name of my image in I get the warning "Incompatible Pointed types sending 'NSString *' to parameter of type 'UIImage *'. – Slider257 May 10 '13 at 17:29
  • When I build and run the app, it crashes after load stating "2013-05-10 13:28:13.356 Scroll Test #543[7701:c07] -[__NSCFConstantString _isDecompressing]: unrecognized selector sent to instance 0x46cc 2013-05-10 13:28:13.359 Scroll Test #543[7701:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString _isDecompressing]: unrecognized selector sent to instance 0x46cc'". Thanks a lot for your help thus far Undo, I really appreciate it. Any idea where I go from here / what I'm doing wrong now? – Slider257 May 10 '13 at 17:29
  • I should also probably mention that I would prefer not to do the imageView in code as ultimately I wish to attach some text fields, buttons and other elements to this scroll view. I'm just trying to actually get something to scroll before I start placing that content. – Slider257 May 10 '13 at 17:52
  • Thanks again for the suggestions Undo. It turns out (and I must have completely missed this during my original lessons) but if you have Auto Layout turned on for your project, the stupid setting completely negates UIScrollView!! Pretty crappy design flaw there Apple. Thankfully I'm back on track and working again, yay! – Slider257 May 11 '13 at 17:45
  • @Slider257 You're welcome. Somehow I missed your comments - but I've edited the post to keep future users from experiencing the same confusion. – Undo May 11 '13 at 17:54