【问题标题】:Take a snapshot of a Group element with WatchKit & save to camera roll使用 WatchKit 拍摄组元素的快照并保存到相机胶卷
【发布时间】:2015-05-22 08:07:29
【问题描述】:

我正在尝试以编程方式拍摄 Group 元素及其内容(文本标签)的快照并将其保存到相机胶卷。

我通常会为 iPhone 应用程序执行类似的操作(参见代码 sn-p),但使用 WatchKit 时,Group 元素的结构与 UIView 不同。

任何帮助将不胜感激。这是我的代码:

    // grab reference to the area you'd like to capture
    WKInterfaceGroup *theArea = _theGroup;

    // define the size and grab a UIImage from it
    UIGraphicsBeginImageContextWithOptions(theArea.bounds.size, theArea.opaque, 0.0);
    [theArea.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *screengrab = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    // save screengrab to Camera Roll
    UIImageWriteToSavedPhotosAlbum(screengrab, nil, nil, nil);

【问题讨论】:

    标签: ios objective-c watchkit apple-watch wkinterfacegroup


    【解决方案1】:

    不幸的是,当前版本的 WatchKit 中没有快照式方法,因此您提到的技术不可用。事实上,可以从 WatchKit 接口读取的属性非常少。

    您能够执行此类操作的唯一方法是,将组呈现为 WatchKit 扩展程序中的图像,然后使用该图像在 Watch 上填充 WKInterfaceImage(或适当的背景图像)。当然,这意味着您必须创建模仿 Watch 控件外观的自定义绘图代码。根据界面的复杂程度,这可能需要大量工作。

    【讨论】:

    • 好的。我喜欢从屏幕上的数据渲染图像的想法。我会这样做的。谢谢迈克。
    • 你的“唯一方法”是没有答案。
    猜你喜欢
    • 2014-09-04
    • 1970-01-01
    • 2013-04-03
    • 1970-01-01
    • 2017-02-06
    • 1970-01-01
    • 2015-08-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多