Skip to content

Instantly share code, notes, and snippets.

@luiseduardohd
Created October 16, 2014 21:50
Show Gist options
  • Save luiseduardohd/1e745621560775b55168 to your computer and use it in GitHub Desktop.
Save luiseduardohd/1e745621560775b55168 to your computer and use it in GitHub Desktop.
This makes uiviewcontroller appears like popup.
// This file has been autogenerated from parsing an Objective-C header file added in Xcode.
using System;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using System.Collections.Generic;
using MonoTouchPlus;
using System.Drawing;
namespace MonoTouchPlus
{
public class SimulatedTransparentViewController : UIViewController
{
public SimulatedTransparentViewController () : base ()
{
Console.Out.WriteLine("SimulatedTransparentViewController () : base ()");
}
//http://stackoverflow.com/questions/587681/how-to-use-presentmodalviewcontroller-to-create-a-transparent-view
public SimulatedTransparentViewController (IntPtr handle) : base (handle)
{
Console.Out.WriteLine("SimulatedTransparentViewController (IntPtr handle) : base (handle)");
}
public SimulatedTransparentViewController (String nibName, NSBundle bundle) : base (nibName,bundle)
{
Console.Out.WriteLine("SimulatedTransparentViewController (String nibName, NSBundle bundle) : base (nibName,bundle)");
}
public override void LoadView ()
{
Console.Out.WriteLine("LoadView ()");
base.LoadView();
/*
* UIGraphicsBeginImageContext(objAppDelegate.window.frame.size);
[objAppDelegate.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIViewController *controllerForBlackTransparentView=[[[UIViewController alloc] init] autorelease];
[controllerForBlackTransparentView setView:viewForProfanity];
UIImageView *imageForBackgroundView=[[UIImageView alloc] initWithFrame:CGRectMake(0, -20, 320, 480)];
[imageForBackgroundView setImage:viewImage];
[viewForProfanity insertSubview:imageForBackgroundView atIndex:0];
[self.navigationController presentModalViewController:controllerForBlackTransparentView animated:YES];
*/
// //UIGraphics.BeginImageContext( UIApplication.SharedApplication.Delegate.Window.Frame.Size );
// UIGraphics.BeginImageContext( UIApplication.SharedApplication.Delegate.Window.Bounds.Size );
// //UIGraphics.BeginImageContext( UIScreen.MainScreen.Bounds.Size );
//
// UIApplication.SharedApplication.Delegate.Window.Layer.RenderInContext(UIGraphics.GetCurrentContext());
// UIImage image = UIGraphics.GetImageFromCurrentImageContext();
// UIGraphics.EndImageContext();
//
// //backgroundImageView = new UIImageView(new RectangleF(0,-20,320,480));
// //backgroundImageView = new UIImageView(new RectangleF(0,-20,this.View.Frame.Width,this.View.Frame.Height));
// //backgroundImageView = new UIImageView(new RectangleF(0,0,this.View.Frame.Width,this.View.Frame.Height));
// var width =UIApplication.SharedApplication.Delegate.Window.Bounds.Width;
// var height =UIApplication.SharedApplication.Delegate.Window.Bounds.Height;
var width =UIScreen.MainScreen.Bounds.Width;
var height =UIScreen.MainScreen.Bounds.Height;
//// var width =UIScreen.MainScreen.Bounds.Size.Width;
//// var height =UIScreen.MainScreen.Bounds.Size.Height;
// //backgroundImageView = new UIImageView(new RectangleF(0,-20,width,height));
// backgroundImageView = new UIImageView(new RectangleF(0,0,width,height));
// backgroundImageView.Image=image;
backgroundImageView = new UIImageView(new RectangleF(0,0,width,height));
backgroundImageView.Image = UIScreen.MainScreen.Capture ();
}
public UIImageView backgroundImageView;
public UIView transparentBlankMask;
public override void ViewDidAppear (bool animated)
{
Console.Out.WriteLine ("ViewDidAppear");
this.View.InsertSubview(backgroundImageView,0);
transparentBlankMask = new UIView(backgroundImageView.Frame);
transparentBlankMask.BackgroundColor = UIColor.Black;
transparentBlankMask.Alpha = 0.0f;
this.View.InsertSubview(transparentBlankMask,1);
UIView.BeginAnimations("transparentBlankMask");
UIView.SetAnimationDuration( 1.00);
transparentBlankMask.Alpha = 0.75f;
UIView.CommitAnimations();
}
public override void DismissViewController (bool animated, NSAction completionHandler)
{
Console.Out.WriteLine ("DismissViewController (bool animated, NSAction completionHandler)");
backgroundImageView.RemoveFromSuperview();
transparentBlankMask.RemoveFromSuperview();
base.DismissViewController(animated, completionHandler);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment