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 · Jan 24, 2016 · 3955 views
    This topic created in 3904 days ago, the information mentioned may be changed or developed.
    通过数据反算 Table View 的 Cell 高度,当包含中文字符的字符串中包含字符 ',' (半角的逗号) 时, Text View 渲染的结果是 2 行文字, Layout Manager 算出来的行数是 3 行,经验证, NSAttributedString 的 boundingRectWithSize 方法也存在这个问题。

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

    Returns the bounding rectangle for the glyphs laid out in the given text container.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2531 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 03:33 · PVG 11:33 · LAX 20:33 · JFK 23:33
    ♥ Do have faith in what you're doing.