So I am aligning my collectionView inside my UITableViewCell, however once I launch the app it displays the width of my storyboard UITableViewCell instead of the actual iPad app itself (that changes once I start scrolling). Here is my current code
collectionView.frame.origin.x = collectionView.superview!.frame.width;
print(collectionView.superview!.frame.width)
The app prints this, it starts printing 728 once I start scrolling.
335.0
335.0
335.0
335.0
335.0
728.0
728.0
728.0
So my question is, why does this happen, and how can I make sure I always get the 728 width when aligning my collectionView?
Here are some images to help (the blue background is collectionView , the red background is collectionView.superview
At first when you run
print(collectionView.superview!.frame.width)
it prints the storyboard encapuslated height = 335 which is the iphone width you developed the layout with to access the right width inisde the vc's
override func viewDidLayoutSubviews()
super.viewDidLayoutSubviews()
// print here
}
or inside the cell
override func layoutSubviews()
super.layoutSubviews()
// print here
}
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.