I'm trying to work around the inability to use custom UI elements in the watchkit. My app is custom-userbutton (MRD Button ) And what I am trying to do is make them using their images on the watchkit interface and as a backdrop for WKInterfaceButton. The problem is that I am not able to convert UIView to UIImage when the view is not visible. This code I am using is giving me an error on drawViewHierarchyInRect
.
- (UIImage *) Convert buttons icon (UghraphicsBeginImageContextWithOptions (Button; Backgrounds, Yes, 0); [Button drawer archiector: button Barriers after the screen: yes]; UIImage * image = UIGraphicsGetImageFromCurrentImageContext (); UIGraphicsEndImageContext (); Return image; }
There is actually no screen / window in the WatchKit extension, so how do we prepare images with ideas?
Instead of VivahirKineRect, try rendering using the renderconnect on the layer.
I just ran in the same problem you did not work by using DrawViewHierarchInRect - just get a black screen but after switching to the renderIncontext, it seems that I have UIIV in my UIView I can change it from the app, while it is in the background (it is visible on the screen without seeing it), and then I can send it to the clock and display it.
Here's what I've used:
+ (UIImage *) imageFromView: (UIView *) See {UIGraphicsBeginImageContextWithOptions (see .boundsize, yes, 0.0); [View.layer renderInContext: UIGraphicsGetCurrentContext ()]; // [ViewViewHareActivity: See. Device after screen: no]; UIImage * Captured Image = UIGraphicsGetImageFromCurrentImageContext (); UIGraphicsEndImageContext (); Image captured upon return; }
Then I use openParentApplication to ping the phone in the Watchkit extension, then in the order of converting UIImage to NSData, pass it back in the handleWatchKitExtensionRequest. It seems that it has been working for me so far, so hopefully it will be for you too. This was done on all simulators, BTW.
No comments:
Post a Comment