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
Jeong
V2EX  ›  iDev

[iOS] NSLayoutManager 计算出的 frame 与 Text View 实际使用的 frame 不一致

  •  
  •   Jeong · 2016-01-24 16:35:14 +08:00 · 2882 次点击
    这是一个创建于 3012 天前的主题,其中的信息可能已经有所发展或是发生改变。
    通过数据反算 Table View 的 Cell 高度,当包含中文字符的字符串中包含字符 ',' (半角的逗号) 时, Text View 渲染的结果是 2 行文字, Layout Manager 算出来的行数是 3 行,经验证, NSAttributedString 的 boundingRectWithSize 方法也存在这个问题。

    这个问题在大多数情况下不会怎么样,但是在有些数据的字符串长度刚好是 Text View 两行能放下的时候,计算出的高度就会比实际需要的高度要大。同时其他类似的字符也会存在类似的问题,比如'.'。有人遇到过类似的问题么?
    3 条回复    2016-01-24 22:32:30 +08:00
    Jeong
        1
    Jeong  
    OP
       2016-01-24 17:00:53 +08:00
    同样的,当实际渲染时,刚好一行能放下的时候,算出来的高度就是两行。之前没发现这个问题,这两天在写的这个应用的数据里,经常有半角的标点符号与中文字符混编的情况,我翻遍了 Text Kitd 的文档,都没有找到可以处理这个事情的 API ,感觉是个 BUG
    jackisnotspirate
        2
    jackisnotspirate  
       2016-01-24 22:30:38 +08:00
    usedRectForTextContainer(_:)

    Returns the bounding rectangle for the glyphs laid out in the given text container.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3304 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 14:10 · PVG 22:10 · LAX 07:10 · JFK 10:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.