iOS Xcode为Subview设置的约束条件在iOS 8 & Xcode 6中出现异常
来源:互联网 发布:使用淘宝联盟微信号 编辑:程序博客网 时间:2024/05/17 04:21
- 问题重述:
为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, NO
otherwise.
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
- iOS Xcode为Subview设置的约束条件在iOS 8 & Xcode 6中出现异常
- [IOS] Xcode中 Search Paths的设置
- iOS:调试时在XCode中添加异常断点
- iOS - Xcode联网设置
- 在xcode 6.4 中设置 ios应用的状态栏的风格
- cocos2d-x在Xcode(iOS )中设置横竖屏的解决方案
- Xcode中(ios) view设置背景图片
- iOS Xcode中设置 横屏,竖屏
- iOS—Xcode中设置Framework Search Paths的秘密!
- Xcode的iOS项目的版本号设置
- Xcode的iOS项目的版本号设置
- iOS 在Xcode中使用C++ Library
- iOS 在 Xcode 中重命名项目名称
- ios如何在xcode中创建文件夹
- iOS 在 Xcode 中重命名项目名称
- 在xcode中修改ios项目名称
- iOS 在 Xcode 中重命名项目名称
- iOS 在Xcode中使用OpenSSL库
- Angular通过CORS实现跨域方案
- 修改u-boot的开机logo及显示过程
- C++中const用法总结
- PHP操作MongoDB
- hdu 2602 Bone Collector(01背包)
- iOS Xcode为Subview设置的约束条件在iOS 8 & Xcode 6中出现异常
- Java正则表达式详解
- summary of exception occured in my development
- baidu 自动下拉框模拟
- Android禁止横屏, include设置布局
- CMake和Boost和OpenCV以及Windows及Mac
- 陌陌聊天记录被删除了,还能恢复吗?QQ1622863529
- 从oracle数据库迁移到db2数据库,图文详细步骤
- POJ 3183 Stump Removal(简单题)