The constraints set by iOS Xcode for Subview are abnormal in iOS 8 & amp; Xcode 6.
Repeat the problem:
A hearderView is designed for collectionview, And the headerView is a custom myview. There is a subview in this custom, and its constraints are set to superview. Running in combination with Xcode 6 and iOS 8, the above subview is not completely in accordance with the original design constraints, but is to reset layout from (0, 0) as the origin. However, the combination of iOS7 + Xcode 5/6 and iOS8 + Xcode 5 is normal.
Solution:
When initializing myview, add:
self.myView.translatesAutoresizingMaskIntoConstraints = YES;
- (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { NSLog(@initWithFrame); [[NSBundle mainBundle] loadNibNamed:@myView owner:self options:nil]; self.myView.translatesAutoresizingMaskIntoConstraints = YES; [self addSubview:self.myView]; } return self;}
Problem Analysis:
TranslatesAutoresizingMaskIntoConstraints:
Returns a Boolean value that indicates whether the view's autoresizing mask is translated into constraints for the constraint-based layout system.
Declaration
SWIFT
func translatesAutoresizingMaskIntoConstraints() -> Bool
OBJECTIVE-C
- (BOOL)translatesAutoresizingMaskIntoConstraints
Return Value
YESIf the view's autoresizing mask is translated into constraints for the constraint-based layout system,NOOtherwise.
Discussion
If this is value isYES, The view's superview looks at the view's autoresizing mask, produces constraints that implement it, and adds those constraints to itself (the superview ).
Import Statement
import UIKit
Availability
Available in iOS 6.0 and later.