1

So I'm trying to put an image in my UI, and I've tried setting the content size.

- (void)viewDidLoad{
    //[super viewDidLoad];
    _trendingImageView.image = [UIImage imageNamed:@"trending.png"];
    [self.scrollView setContentSize:CGSizeMake(2000, 2000)];
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear: animated];
    NSLog(@"VIEW WILL APPEAR BEING CALLED");
    self.rateView.notSelectedStar =[UIImage imageNamed:@"star-off.png"];
    self.rateView.fullSelectedStar = [UIImage imageNamed:@"star-on.png"];
    self.rateView.rating = self.rating;
    self.rateView.editable = YES;
    self.rateView.maxRating = 5;
    self.rateView.delegate = self;
    _pageTitleLabel.text = _pageTitle;
    //_pageScoreLabel.text = _pageScore;
    _trendingImageView.image = [UIImage imageNamed:@"trending.png"];
    _restaurantImageView.image = _restaurantImage;
    _descriptionView.text = _description;
    [self.scrollView setContentSize:CGSizeMake(2000,2000)];
}

The scrollView var is connected to a scroll view in the interface builder. This scroll view is inside another view, and it has subviews.

Why is this not scrolling?

This is the scrollView-

SCROLL VIEW : <UIScrollView: 0xac73010; frame = (0 -108; 320 676); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0xac73bd0>; layer = <CALayer: 0xac731e0>; contentOffset: {0, 0}>
praks5432
  • 7,246
  • 32
  • 91
  • 156

1 Answers1

0

Add this lines in your viewDidLoad method:

   self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 2000, 2000)];
   [self.scrollView setScrollEnabled:YES];
   [self.scrollView setClipsToBounds:YES];
   self.scrollView.delegate = self;

Also make sure that you conform to <UIScrollViewDelegate> in your .h file. Finally there is no need to set contentsize to both viewDidLoad and viewWillAppear. Leave it only in viewDidLoad.

Nikos M.
  • 13,685
  • 4
  • 47
  • 61
  • The delegate has nothing to do with getting the scroll view to scroll. – rdelmar Dec 17 '13 at 06:03
  • wait - so do I need to implement all this? https://developer.apple.com/library/ios/documentation/uikit/reference/uiscrollviewdelegate_protocol/Reference/UIScrollViewDelegate.html – praks5432 Dec 17 '13 at 06:07
  • He already has a scroll view that he added in IB. Why would he create a new one? Also, if you make the frame the same size as the contentView it won't scroll. – rdelmar Dec 17 '13 at 06:07
  • rdelmar - do you have any ideas as to what the problem might be? – praks5432 Dec 17 '13 at 06:08
  • @praks5432, you might want to for other purposes, but you don't need to implement the delegate protocol to make a scroll view scroll. – rdelmar Dec 17 '13 at 06:09
  • If you do no not implement the delegate protocol and you use scrollView delegate methods, you will get a warning. – Nikos M. Dec 17 '13 at 06:10
  • ok...so I added @interface BasicCardViewController : UIViewController - is that all I need? – praks5432 Dec 17 '13 at 06:11
  • also, Nikos - I've already added a scroll view in interface builder - why am I allocing a new one? Instead of allocing that, I tried the other three lines - still no dice – praks5432 Dec 17 '13 at 06:12
  • Your scrollview as set in IB has this frame: frame = (0 -108; 320 676); y parameter is unusual. Post a screenshot from your xib file – Nikos M. Dec 17 '13 at 06:13
  • er..so it *looks* ok in interface builder – praks5432 Dec 17 '13 at 06:15
  • are you using autolayout and ios 7? – Shabir jan Dec 17 '13 at 06:16
  • yeah I am - I saw that, that might interfere, so I unchecked it - same problem – praks5432 Dec 17 '13 at 06:17
  • wait - I just tried again - that totally fixed it - but what if I want it to scroll even when I turn it sideways? – praks5432 Dec 17 '13 at 06:18
  • If you have your autoresizing masks correct, landscape mode shouldn't be an issue – Nikos M. Dec 17 '13 at 07:33