Autolayout problems with iOS8 with code that works fine on iOS7

前端 未结 3 1565
悲哀的现实
悲哀的现实 2020-12-01 07:56

I\'m in the midst of developing an app for the iPhone and iPad. It supports iOS6 and iOS7 and it uses auto layout exclusively.

This past week, when Apple announce

3条回答
  •  自闭症患者
    2020-12-01 08:29

    You might find the answers to this question helpful: UICollectionView cell subviews do not resize

    In most cases the works in iOS7 but not on iOS 8 auto layout problems seem to stem from the root view not being sized correctly in iOS 8, particularly when we set translatesAutoresizingMaskIntoConstraints to NO. For my views I was able to set the root view's frame in layoutSubviews (or whichever appropriate initializer that does have the correct bounds) and this resolved the issue.

    self.contentView.frame = CGRectInset(self.bounds, 0, 0);
    

    As shown in the answer above, you could also do

    self.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    

    and then turn translatesAutoresizingMaskIntoConstraints back to NO before you start setting your own constraints in code.

    Definitely hate that so much of our time is taken with these annoying gotchas.

提交回复
热议问题