iOS Xcode为Subview设置的约束条件在iOS 8 & Xcode 6中出现异常
2014-09-25 20:20
435 查看
问题重述:
为collectionview设计了一个hearderView,而这个headerView是一个自定义的myview,在这个自定义中有一个subview,它的约束条件是设置到superview的。在Xcode 6和iOS 8的组合下运行,上述的subview完全没有按照原来设计的约束,而是以从(0,0)为原点自己重置layout。但在iOS7 + Xcode 5/6 和iOS8 + Xcode 5 的组合中是正常的。
解决方案:
在初始化myview的时候,添加:
问题分析:
translatesAutoresizingMaskIntoConstraints:
Returns a Boolean value that indicates whether the view’s autoresizing mask is translated into constraints for the constraint-based layout system.
SWIFT
OBJECTIVE-C
the view’s autoresizing mask is translated into constraints for the constraint-based layout system,
If this is value is
the view’s superview looks at the view’s autoresizing mask, produces constraints that implement it, and adds those constraints to itself (the superview).
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
为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
SWIFTfunc 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 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开发异常]whose view&n…
- Ios 该图显示其出现的相关问题定义UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
- UITableView在约束正确设置的情况下出现顶部空白区域
- Xcode9 iOS 11 使用MJRefresh TableView出现异常。
- iOS开发的一些小技术:让UIImage有缩放功能、控制log的输出、xcode修改文件注释、随机数的使用、在UIImageView 中旋转图像、在Quartz中如何设置旋转点、创建.plist文件并存储
- IOS StoryBoard 中 alpha设置 导致subview中的控件也透明了
- iOS XCode storyboard 设置控件三等分屏幕的约束添加
- 条件断点 设置 出现异常
- 设置Xcode 4同时支持旧版iOS…
- IOS 设置icon 出现的bug The app icon set named "AppIcon" did not have any applicable content.
- [Xcode]_[解决Xcode设置断点,调试窗口出现反汇编代码的异常情况]
- iOS UITableView设置tableHeaderView时发生约束错误 UIView-Encapsulated-Layout-Height UIView-Encapsulated-Layout-Width
- xcode在调试带有webview的页面时出现SIGKill异常
- iOS-使用VPImageCropper时Analyze 出现Potential leak of an object stored into 'subImageRef'
- (启动H5本地存储)WebView显示网页出现Uncaught TypeError: Cannot call method 'getItem' of null异常
- iOS tableView 在设置了footView的情况下,系统自带分割线时而消失,时而出现的问题
- iOS开发:Xcode 7之后viewForHeaderInSection、viewForFooterInSection设置内容不产生效果的解决方法
- 当RecycleView跟ScrollView冲突设置自定义LinearLayoutManager的时候出现IllegalArgumentException异常
- iOS:在tableView中通过Masonry使用autolayout在iOS7系统出现约束崩溃
- iOS开发出现的错误:loaded the "VCRoot" nib but the view outlet was not set.'