V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
babyname
V2EX  ›  iDev

请教一个 autolayout,总是提示约束冲突

  •  
  •   babyname · 2015-01-21 17:54:05 +08:00 · 1946 次点击
    这是一个创建于 3384 天前的主题,其中的信息可能已经有所发展或是发生改变。

    结构

    如图,我用 A 方法和 B 方法都提示冲突

    前提: green view 必须有高度约束的 50

    A布局中:
    red 距离 super view top 10
    green 距离 red view top 10
    green 距离 super view bottom 20

    此时提示 green 冲突了,不能同时满足 height 和 距离 super view bottom 20

    B布局中:
    red 距离 super view top 10
    green 距离 red view top 10
    purple 距离 green view top 0
    purple 距离 super view bottom 20

    此时还是提示冲突,怎么满足 green view 必须有高度约束呢?

    这是一个 uitableviewcell 的布局,bottom也必须要有 Pin,否则自动检测高度无效。

    相关代码
    titleLabel.autoPinEdgeToSuperviewEdge(ALEdge.Top, withInset: verticalInsets)
    titleLabel.autoPinEdgeToSuperviewEdge(ALEdge.Left, withInset: horizontalInsets)
    titleLabel.autoPinEdgeToSuperviewEdge(ALEdge.Right, withInset: horizontalInsets)
    dateLabel.autoPinEdgeToSuperviewEdge(ALEdge.Left, withInset: horizontalInsets)
    dateLabel.autoPinEdge(ALEdge.Top, toEdge: ALEdge.Bottom, ofView: titleLabel, withOffset: verticalInsets / 2)
    //
    coverImage.autoPinEdge(ALEdge.Top, toEdge: ALEdge.Bottom, ofView: dateLabel, withOffset: verticalInsets)
    coverImage.autoPinEdgeToSuperviewEdge(ALEdge.Left, withInset: horizontalInsets)
    coverImage.autoPinEdgeToSuperviewEdge(ALEdge.Right, withInset: horizontalInsets)
    coverImage.autoSetDimension(ALDimension.Height, toSize: screenWidth * 0.5597014925)
    //
    bottomGap.autoPinEdge(ALEdge.Top, toEdge: ALEdge.Bottom, ofView: coverImage)
    bottomGap.autoPinEdgeToSuperviewEdge(ALEdge.Bottom, withInset: verticalInsets)

    3 条回复
    Shane
        1
    Shane  
       2015-01-21 21:38:29 +08:00 via iPhone
    定义了top和bottom两个约束,肯定和固定height冲突啊,按你的意思,把top去掉不就可以了,另外,什么叫“自动检测高度无效”
    cralison
        2
    cralison  
       2015-01-22 04:19:03 +08:00
    是这样的,height不能同时设top和bottom,width不能同时设leading和trailing,因为这从逻辑上就说不通。
    babyname
        3
    babyname  
    OP
       2015-01-22 09:11:16 +08:00
    @cralison
    @Shane
    嗯,我height使用比例约束就好了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4963 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 09:46 · PVG 17:46 · LAX 02:46 · JFK 05:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.