iOS Xcode set constraints for Subview exception in iOS 8 & Xcode 6

Source: Internet
Author: User

    • Restatement of the problem:

A hearderview is designed for CollectionView, and this headerview is a custom myview, with a subview in this customization, and its constraints are set to Superview. Running under the combination of Xcode 6 and iOS 8, the above-mentioned Subview completely did not follow the original design constraints, but instead reset the layout itself from (0,0) to the original point. However, it is normal in the combination of IOS7 + Xcode 5/6 and IOS8 + Xcode 5.

    • Solution:

When initializing the 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 to constraints for the Constra int-based layout System.

Declaration

SWIFT

func translatesAutoresizingMaskIntoConstraints() -> Bool

Objective-c

- (BOOL)translatesAutoresizingMaskIntoConstraints

Return Value

YESIf the view ' s autoresizing mask is translated to constraints for the constraint-based layout system, NO otherwise.

Discussion

If This YES is value, 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.

    • Reference Links:

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 set constraints for Subview exception in iOS 8 & Xcode 6

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.