Re: Snapshotting hidden UIViews
On Jan 13, 2010, at 10:30 PM, glenn andreas wrote: On Jan 13, 2010, at 9:46 PM, Michael Gardner gardne...@gmail.com wrote: On Jan 13, 2010, at 5:07 PM, glenn andreas wrote: On Jan 13, 2010, at 4:48 PM, Michael Gardner wrote: I also tried calling -drawRect: on my hidden view (after setting the context with UIGraphicsBeginImageContext()), but it doesn't seem to do anything. Many built in views do not draw anything at all (and have no useful drawRect:) - all of their rendering is handled by the view's layer. Ah, that explains that. But I'd still very much like to know why the layer's -renderInContext: doesn't work consistently when the view is hidden. Pure speculation, but a hidden view may not have a layer associated with it, and things like subview layout aren't done for hidden views (why waste cycle laying out the subviews if nobody will see it?). There are probably other undocumented optimizations as well on hidden views, such as animations not running, pending refreshes postponed, etc... UIWebView is going to be especially problematic, since it does a whole lot of things in the background (such as loading needed images and other resources) That still leaves the question of how to capture the contents of a UIView in an image when the view isn't visible. By the way, I tried the trick Matt suggested earlier in the thread, by obscuring my view behind another one instead of making it hidden. It didn't work. Is UIKit smart enough to know that a view behind another (opaque) view is effectively hidden? -Michael___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Snapshotting hidden UIViews
You could try making it not opaque (i.e. have isOpaque return NO). Then the view should get drawn, even if it is subsequently over-painted by another view positioned on top of it. That's how it works in Cocoa, at least. Calling setNeedsDisplay on the (common) parent view ought to do it but you will need to return to the run loop before anything actually happens of course. Paul Sanders. - Original Message - From: Michael Gardner gardne...@gmail.com To: cocoa-dev@lists.apple.com Sent: Thursday, January 14, 2010 5:22 PM Subject: Re: Snapshotting hidden UIViews By the way, I tried the trick Matt suggested earlier in the thread, by obscuring my view behind another one instead of making it hidden. It didn't work. Is UIKit smart enough to know that a view behind another (opaque) view is effectively hidden? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Snapshotting hidden UIViews
On Thu, 14 Jan 2010 11:22:19 -0600, Michael Gardner gardne...@gmail.com said: By the way, I tried the trick Matt suggested earlier in the thread, by obscuring my view behind another one instead of making it hidden. It didn't work. Yes, because that isn't what I said to do. And since you're on iPhone, what I suggested doing (covering the window with another *window*) probably isn't even possible. Sorry about that. In the iPhone version of my JACT Vocab app, I rewrote the entire animation approach so as not to need a snapshot at all... m. -- matt neuburg, phd = m...@tidbits.com, http://www.tidbits.com/matt/ A fool + a tool + an autorelease pool = cool! AppleScript: the Definitive Guide - Second Edition! http://www.tidbits.com/matt/default.html#applescriptthings ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Snapshotting hidden UIViews
On Tue, 12 Jan 2010 14:18:05 -0600, Michael Gardner gardne...@gmail.com said: I'm trying to create a snapshot UIImage from a UITextView that's inside a larger, hidden UIView. renderInContext: works fine for visible UIView layers, but I can't get consistent results for hidden views. I read somewhere (can't recall the source, but it wasn't authoritative) that this is expected behavior, and that -renderInContext: is only guaranteed to work for visible UIViews' layers. Is this true? If so, how else can I replicate *exactly* what my UITextView would look like when visible? In my JACTVocab app I have a similar problem: I need to make a snapshot of a situation in my window that doesn't exist yet. In other words, my window is in situation A, but I need a snapshot of situation B. I will eventually show the user situation B, but I need the snapshot first. So what I do is: I take a snapshot of situation A, and cover the window with a borderless window containing that snapshot. This hides what I am about to do in the real window. Now I change the situation in the window to situation B. The user cannot see this happening because snapshot of situation A is covering the window. Now I take the snapshot of situation B (this works perfectly well even though the second window is covering it). The hand is quicker than the eye, and the user never notices (I hope). Also, I use cacheDisplayInRect, not renderInContext. But it may be that there are reasons why you don't have that option... Hope this helps some - m. -- matt neuburg, phd = m...@tidbits.com, http://www.tidbits.com/matt/ A fool + a tool + an autorelease pool = cool! AppleScript: the Definitive Guide - Second Edition! http://www.tidbits.com/matt/default.html#applescriptthings ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Snapshotting hidden UIViews
On Jan 13, 2010, at 11:24 AM, Matt Neuburg wrote: On Tue, 12 Jan 2010 14:18:05 -0600, Michael Gardner gardne...@gmail.com said: I'm trying to create a snapshot UIImage from a UITextView that's inside a larger, hidden UIView. renderInContext: works fine for visible UIView layers, but I can't get consistent results for hidden views. I read somewhere (can't recall the source, but it wasn't authoritative) that this is expected behavior, and that -renderInContext: is only guaranteed to work for visible UIViews' layers. Is this true? If so, how else can I replicate *exactly* what my UITextView would look like when visible? In my JACTVocab app I have a similar problem: I need to make a snapshot of a situation in my window that doesn't exist yet. In other words, my window is in situation A, but I need a snapshot of situation B. I will eventually show the user situation B, but I need the snapshot first. So what I do is: I take a snapshot of situation A, and cover the window with a borderless window containing that snapshot. This hides what I am about to do in the real window. Now I change the situation in the window to situation B. The user cannot see this happening because snapshot of situation A is covering the window. Now I take the snapshot of situation B (this works perfectly well even though the second window is covering it). The hand is quicker than the eye, and the user never notices (I hope). Also, I use cacheDisplayInRect, not renderInContext. But it may be that there are reasons why you don't have that option... Hope this helps some - m. Thanks for this useful tip, but I hope I don't have to resort to your method. It just feels... dirty, you know? I'm not using -cacheDisplayInRect: because it doesn't exist in UIView, as far as I know. I also tried calling -drawRect: on my hidden view (after setting the context with UIGraphicsBeginImageContext()), but it doesn't seem to do anything. -Michael___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Snapshotting hidden UIViews
On Jan 13, 2010, at 4:48 PM, Michael Gardner wrote: I also tried calling -drawRect: on my hidden view (after setting the context with UIGraphicsBeginImageContext()), but it doesn't seem to do anything. Many built in views do not draw anything at all (and have no useful drawRect:) - all of their rendering is handled by the view's layer. Glenn Andreas gandr...@gandreas.com The most merciful thing in the world ... is the inability of the human mind to correlate all its contents - HPL ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Snapshotting hidden UIViews
On Jan 13, 2010, at 5:07 PM, glenn andreas wrote: On Jan 13, 2010, at 4:48 PM, Michael Gardner wrote: I also tried calling -drawRect: on my hidden view (after setting the context with UIGraphicsBeginImageContext()), but it doesn't seem to do anything. Many built in views do not draw anything at all (and have no useful drawRect:) - all of their rendering is handled by the view's layer. Ah, that explains that. But I'd still very much like to know why the layer's -renderInContext: doesn't work consistently when the view is hidden. -Michael___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Snapshotting hidden UIViews
On Jan 13, 2010, at 9:46 PM, Michael Gardner gardne...@gmail.com wrote: On Jan 13, 2010, at 5:07 PM, glenn andreas wrote: On Jan 13, 2010, at 4:48 PM, Michael Gardner wrote: I also tried calling -drawRect: on my hidden view (after setting the context with UIGraphicsBeginImageContext()), but it doesn't seem to do anything. Many built in views do not draw anything at all (and have no useful drawRect:) - all of their rendering is handled by the view's layer. Ah, that explains that. But I'd still very much like to know why the layer's -renderInContext: doesn't work consistently when the view is hidden. Pure speculation, but a hidden view may not have a layer associated with it, and things like subview layout aren't done for hidden views (why waste cycle laying out the subviews if nobody will see it?). There are probably other undocumented optimizations as well on hidden views, such as animations not running, pending refreshes postponed, etc... UIWebView is going to be especially problematic, since it does a whole lot of things in the background (such as loading needed images and other resources) ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com