標籤:des style http color io os ar strong for
為collectionview設計了一個hearderView,而這個headerView是一個自訂的myview,在這個自訂中有一個subview,它的約束條件是設定到superview的。在Xcode 6和iOS 8的組合下運行,上述的subview完全沒有按照原來設計的約束,而是以從(0,0)為原點自己重設layout。但在iOS7 + Xcode 5/6 和iOS8 + Xcode 5 的組合中是正常的。
在初始化myview的時候,添加:
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;}
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
YES if the view’s autoresizing mask is translated into constraints for the constraint-based layout system, NOotherwise.
Discussion
If this is value is YES, 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.
https://developer.apple.com/library/IOs/documentation/UIKit/Reference/UIView_Class/index.html#//apple_ref/occ/instm/UIView/translatesAutoresizingMaskIntoConstraints
http://stackoverflow.com/questions/25817609/constraints-for-subview-not-working-in-ios-8-xcode-6-6a313-works-ios-7
iOS Xcode為Subview設定的約束條件在iOS 8 & Xcode 6中出現異常