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.

  • 参考链接:

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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值