MacDev 板


LINE

自问自答 如果遇到相同问题的人可以参考这篇,这篇是原因 http://ppt.cc/JTOM Constraints relate two views. In a view NIB, the superview isn't present, so there's nothing for the constraints to relate to. Furthermore, the constraints would have to be added to the superview, not to the view in the NIB. Lastly, one important use case for a view NIB is for views which may be used in various contexts. It is not appropriate for the view to dictate how it will relate to its environs in arbitrary contexts. That's a job for the controller which loads it and adds it into a another view hierarchy. 这是一个解法 http://ppt.cc/3Vmt Dragging in a UIView from the Object Library produces a Static view. and Static view: the default views which do not allow top level constraints, and have translatesAutoresizingMaskIntoConstraints set to YES. 所以解法就是设定constrainable view 可以新增也可以转换现有的view ※ 引述《livingProj (活着计画)》之铭言: : 我利用xib建立一个自订的view物件 : 之後在storyboard上拖曳一个view进来,并指定custom class来建立自订的view物件 : 执行之後物件确实建立了 : 但问题是尺寸不对 : 设定部份 : 因为xib里面的view(container),size是设定为inferred : 所以size inspector里的x, y, width, height都是反白无法设定的 : 且显示为(0, 0, 600, 600) : 而我将自订的view物件拉进storyboard以後 : 我设定了width & height的constraint(300, 200) : 但执行以後,view的尺寸还是维持原先的600, 600 : 并没有更新为我所设定的constraint : 我在initWithCoder查看,发现self.bounds.size是正确的数值(300, 200) : 但self.view.bounds.size却是(600,600) : 并没有自己去设定为真正的尺寸 : 如果我多一行程式,将self.view的尺寸设定为self的尺寸 : 问题就解决了 : 但不知道有没有其他的方式或是设定 : 我有试着要在xib里面去设定作为container的view的constraint,但完全无法设定 : 另外还有一个问题,不知道是否与这有关 : 我看网路上很多教学说 : 要加一个设定 : setTranslatesAutoresizingMaskIntoConstraints:NO : 来避免与之前的autosizing产生冲突 : 但如果我加了这一行 : 所有的constraint就失效了,但也无法用直接指定的方式去更改frame : 不知道这是怎麽一回事 : 附上自订类别的.m档 : #import "MyHeader.h" : @interface MyHeader () { : CGSize _intrinsicContentSize; : } : @end : @implementation MyHeader : - (id)initWithCoder:(NSCoder *)aDecoder { : self = [super initWithCoder:aDecoder]; : if (self == nil) { : return nil; : } : [self setupView]; : return self; : } : - (void)setupView { : NSString *nibName = NSStringFromClass(self.class); : UINib *nib = [UINib nibWithNibName:nibName bundle:nil]; : [nib instantiateWithOwner:self options:nil]; : // [self.view setTranslatesAutoresizingMaskIntoConstraints:NO]; : //加了上面这行,排版就会有错误 : _intrinsicContentSize = self.bounds.size; : self.view.frame = CGRectMake(0, 0, _intrinsicContentSize.width, : _intrinsicContentSize.height); : [self addSubview:self.view]; : } : - (CGSize)intrinsicContentSize { : return _intrinsicContentSize; : } --



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 111.251.42.56
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/MacDev/M.1425620803.A.FCA.html ※ 编辑: livingProj (111.251.42.56), 03/06/2015 14:04:18







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:BuyTogether站内搜寻

TOP