The constraints set by iOS Xcode for Subview are abnormal in iOS 8 & amp; Xcode 6.

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.