你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS Xcode為Subview設置的約束條件在iOS 8 & Xcode 6中出現異常

iOS Xcode為Subview設置的約束條件在iOS 8 & Xcode 6中出現異常

編輯:IOS開發綜合

 

問題重述:

 

為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.

 

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved