1

I have a UIViewController with UIScrollView inside. The scroll view automatically adjust its frame according with device screen. My problem is that in the code I can't read the correct frame of scroll view. self.scrollView.frame always return {{0, 0}, {600, 600}} that's the default size of view controller in Interface Builder xib.

I have tried in viewDidLoad and in loadView methods but the frame is still {{0, 0}, {600, 600}}.

- (void)viewDidLoad {

    [super viewDidLoad];

    self.scrollView.pagingEnabled = YES;
    self.scrollView.delegate = self;

    NSLog(@"%@",NSStringFromCGRect(self.scrollView.frame));
}

Ideas ?

dandan78
  • 13,328
  • 13
  • 64
  • 78
Fry
  • 6,235
  • 8
  • 54
  • 93

2 Answers2

1

You can get the correct frame in the -(void)viewDidLayoutSubviews methods of your viewController

Tekaya Marouene
  • 620
  • 3
  • 14
0

when ever you need correct frame after apply layout constraints
write below two lines

[self.view setNeedsLayout];
[self.view layoutIfNeeded]; 
Jageen
  • 6,345
  • 2
  • 37
  • 56