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 ?
您可以在viewController的-(void)viewDidLayoutSubviews
方法中获得正确的帧
when ever you need correct frame after apply layout constraints
write below two lines
[self.view setNeedsLayout];
[self.view layoutIfNeeded];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.