从 UIView 捕获 UIImage 然后在 WatchKit WKInterfaceImage 中使用它
Capture UIImage from UIView then use it in WatchKit WKInterfaceImage
所以我认为我使用与此基本类似的函数以编程方式拍摄快照:
func captureImage() -> UIImage{
UIGraphicsBeginImageContextWithOptions(bounds.size, false, 0.0)
drawViewHierarchyInRect(self.bounds, afterScreenUpdates: true)
// old style: layer.renderInContext(UIGraphicsGetCurrentContext())
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
函数按预期工作,returns UIImage。
我需要知道的是:有没有一种方法可以在不打开实际 iPhone 应用程序的情况下从 WatchKit 扩展程序触发时捕获 UIView 的 UIImage,然后如何检索该图像并将其显示为WKInterfaceImage?
您可以将此图像另存为 NSData 到您共享的用户默认值。
引自 App Extension 编程指南:https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW1
然后从 WatchKit Extension 中检索它。但是,如果您想要某种触发器。您可以使用此 class 方法
+ openParentApplication:reply:
在后台告诉您的包含 iOS 做某事。并在App Delegate中实现其委托方法func application(application: UIApplication!, handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]!, reply: (([NSObject : AnyObject]!) -> Void)!)
所以我认为我使用与此基本类似的函数以编程方式拍摄快照:
func captureImage() -> UIImage{
UIGraphicsBeginImageContextWithOptions(bounds.size, false, 0.0)
drawViewHierarchyInRect(self.bounds, afterScreenUpdates: true)
// old style: layer.renderInContext(UIGraphicsGetCurrentContext())
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
函数按预期工作,returns UIImage。
我需要知道的是:有没有一种方法可以在不打开实际 iPhone 应用程序的情况下从 WatchKit 扩展程序触发时捕获 UIView 的 UIImage,然后如何检索该图像并将其显示为WKInterfaceImage?
您可以将此图像另存为 NSData 到您共享的用户默认值。
引自 App Extension 编程指南:https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW1
然后从 WatchKit Extension 中检索它。但是,如果您想要某种触发器。您可以使用此 class 方法
+ openParentApplication:reply:
在后台告诉您的包含 iOS 做某事。并在App Delegate中实现其委托方法func application(application: UIApplication!, handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]!, reply: (([NSObject : AnyObject]!) -> Void)!)