Opentk/Source/Samples/iOS/ES11/OpenGLViewController.cs
2016-06-08 15:15:59 +09:00

72 lines
2 KiB
C#

using System;
using OpenTK;
using OpenTK.Graphics.ES20;
using OpenTK.Platform.iPhoneOS;
using Foundation;
using CoreAnimation;
using ObjCRuntime;
using OpenGLES;
using UIKit;
namespace ES11
{
[Register("OpenGLViewController")]
public partial class OpenGLViewController : UIViewController
{
public OpenGLViewController(IntPtr handle) : base(handle)
{
}
new EAGLView View { get { return (EAGLView)base.View; } }
public override void ViewDidLoad()
{
base.ViewDidLoad();
NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.WillResignActiveNotification, a =>
{
if (IsViewLoaded && View.Window != null)
View.StopAnimating();
}, this);
NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.DidBecomeActiveNotification, a =>
{
if (IsViewLoaded && View.Window != null)
View.StartAnimating();
}, this);
NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.WillTerminateNotification, a =>
{
if (IsViewLoaded && View.Window != null)
View.StopAnimating();
}, this);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
NSNotificationCenter.DefaultCenter.RemoveObserver(this);
}
public override void DidReceiveMemoryWarning()
{
// Releases the view if it doesn't have a superview.
base.DidReceiveMemoryWarning();
// Release any cached data, images, etc that aren't in use.
}
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
View.StartAnimating();
}
public override void ViewWillDisappear(bool animated)
{
base.ViewWillDisappear(animated);
View.StopAnimating();
}
}
}