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

來源:互聯網
上載者:User

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

 

問題重述:

 

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

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.