【问题标题】:Auto-flowing layout with embedded controls and automatically breaking text带有嵌入式控件和自动中断文本的自动流动布局
【发布时间】:2013-01-17 19:09:31
【问题描述】:

我正在尝试为我的 iPhone 和 iPad 应用程序创建一个基于动态数据自动重排的布局。 更具体一点,这意味着我有几个对象。每个对象都有特定的类型和相关的数据。 data 是应该显示的内容,type 决定了它应该如何显示。一个类型可以是 text,这意味着它应该显示为简单的文本,没有交互的可能性。另一种类型可能是 date,这意味着它应该显示为一个控件,让用户在点击时选择日期。

现在,问题是我要显示的对象的数量和相关数据是动态的,因此我无法将控件放置在静态位置。

This jsfiddle 显示我的意思是哪种布局。根据div 的宽度,内容会自动重新排列,日期输入控件会出现在文本中间。

我找不到任何支持这种情况的控件 - 那么我该如何实现呢?

【问题讨论】:

  • 听起来像是 HTML 的工作?
  • @eggyal:我想使用本机小部件。

标签: ios


【解决方案1】:

Here 是使用 CoreText 解决部分相似问题的示例。也许这会为你指明那个方向。

- (CFArrayRef)copyRectangularPathsForPath:(CGPathRef)path 
                                   height:(CGFloat)height {
    CFMutableArrayRef paths = CFArrayCreateMutable(NULL, 0, 
                                                   &kCFTypeArrayCallBacks);

    // First, check if we're a rectangle. If so, we can skip the hard parts.
    CGRect rect;
    if (CGPathIsRect(path, &rect)) {
        CFArrayAppendValue(paths, path);
    }
    else {
        // Build up the boxes one line at a time. If two boxes have the 
        // same width and offset, then merge them.
        CGRect boundingBox = CGPathGetPathBoundingBox(path);
        CGRect frameRect = CGRectZero;
        for (CGFloat y = CGRectGetMaxY(boundingBox) - height; 
                     y > height; y -= height) {
            CGRect lineRect =
                   CGRectMake(CGRectGetMinX(boundingBox), y, 
                              CGRectGetWidth(boundingBox), height);
            CGContextAddRect(UIGraphicsGetCurrentContext(), lineRect);

            // Do the math with full precision so we don't drift, 
            // but do final render on pixel boundaries.
            lineRect = CGRectIntegral(clipRectToPath(lineRect, path));
            CGContextAddRect(UIGraphicsGetCurrentContext(), lineRect);

            if (! CGRectIsEmpty(lineRect)) {
                if (CGRectIsEmpty(frameRect)) {
                    frameRect = lineRect;
                }
                else if (frameRect.origin.x == lineRect.origin.x && 
                         frameRect.size.width == lineRect.size.width) {
                    frameRect = CGRectMake(lineRect.origin.x,                                                                                                                                      lineRect.origin.y,                                                                                                                                      lineRect.size.width, 
                                CGRectGetMaxY(frameRect) - CGRectGetMinY(lineRect));
                }
                else {
                    CGMutablePathRef framePath =
                                         CGPathCreateMutable();
                    CGPathAddRect(framePath, NULL, frameRect);
                    CFArrayAppendValue(paths, framePath);

                    CFRelease(framePath);
                    frameRect = lineRect;
                }
            }
        }

        if (! CGRectIsEmpty(frameRect)) {
            CGMutablePathRef framePath = CGPathCreateMutable();
            CGPathAddRect(framePath, NULL, frameRect);
            CFArrayAppendValue(paths, framePath);
            CFRelease(framePath);
        }           
    }

    return paths;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-15
    • 2013-04-29
    • 2015-09-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多