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
  • 12,893
  • 12
  • 63
  • 75
Fry
  • 6,125
  • 8
  • 51
  • 90

2 Answers2

1

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

Tekaya Marouene
  • 610
  • 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,265
  • 2
  • 34
  • 55