iPhone/iPad question how to show dialog + how to make screenshot of screen?
I need to show dialog in my iPhone/iPad app (kind of like in Photos, left bottom button which opens dialog with choices "Email Photo", "MMS", "Assign to Contact", "Use a Wallpaper", etc...) -- is it possible? How this view element is called?
And the second questions - is somewhat related. One of the options would be "Email Current Screen", which needs to make screenshot of current screen (obviously without this dialog :-) and open in email to send an ema开发者_如何学编程il. Please suggest how can I make screenshot? I force it to attach to the email? Thanks!
To your first question: it's called an action sheet, and is represented by the UIActionSheet
class. On the iPhone, you can display it in your view using its -showInView:
method; on the iPad, you can display it from a toolbar button with the -showFromBarButtonItem:animated:
method, or from an arbitrary rectangle in a view with -showFromRect:inView:animated:
. Note that since these are two separate code paths, you'll want to use the UI_USER_INTERFACE_IDIOM()
macro (Google it) to determine what type of device your code's running on.
here is the question which deals with taking the screen shot
How to capture current view screenshot and reuse in code? (iPhone SDK)
Here's the answer, in MonoTouch (.NET):
public class ScreenShot
{
public static UIImage TakeScreenShot (UIView view)
{
RectangleF canvasRect = view.Bounds;
UIGraphics.BeginImageContext (canvasRect.Size);
CGContext ctx = UIGraphics.GetCurrentContext ();
ctx.FillRect (canvasRect);
view.Layer.RenderInContext (ctx);
UIImage newImage = UIGraphics.GetImageFromCurrentImageContext ();
UIGraphics.EndImageContext ();
return newImage;
}
}
精彩评论