Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using MonoTouch.Dialog;
- using MonoTouch.UIKit;
- using MonoTouch;
- using MonoTouch.Foundation;
- using MonoTouch.ObjCRuntime;
- namespace SMSMaster
- {
- public partial class mainController : UIViewController
- {
- private NSObject notificationObserver;
- public mainController ()
- {
- }
- public mainController (IntPtr p) : base(p)
- {
- }
- public override void ViewWillAppear (bool animated)
- {
- }
- public override void ViewDidLoad ()
- {
- notificationObserver = NSNotificationCenter.DefaultCenter.AddObserver("UIDeviceOrientationDidChangeNotification", DeviceRotated );
- }
- public override void ViewDidAppear (bool animated)
- {
- UIDevice.CurrentDevice.BeginGeneratingDeviceOrientationNotifications();
- }
- public override void ViewWillDisappear (bool animated)
- {
- UIDevice.CurrentDevice.EndGeneratingDeviceOrientationNotifications();
- }
- public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation)
- {
- return true;
- }
- private void DeviceRotated(NSNotification notification){
- reloadView();
- }
- private void reloadView()
- {
- float x = 0;
- float y = 0;
- float height = 0;
- float width = 0;
- float adX = 0;
- float adY = 0;
- switch(UIDevice.CurrentDevice.Orientation)
- {
- case UIDeviceOrientation.LandscapeLeft:
- case UIDeviceOrientation.LandscapeRight:
- x = 0;
- y = 300;
- adX = 0;
- adY = 690;
- height = 650;
- width = 704;
- break;
- case UIDeviceOrientation.Portrait:
- case UIDeviceOrientation.PortraitUpsideDown:
- x = 0;
- y = 0;
- adX = 0;
- adY = 690;
- height = 500;
- width = 600;
- break;
- default:
- if(Application.window.Frame.Width > Application.window.Frame.Height)
- {
- x = 0;
- y = 300;
- adX = 0;
- adY = 690;
- height = 650;
- width = 704;
- }
- else
- {
- x = 0;
- y = 0;
- adX = 0;
- adY = 960;
- height = 500;
- width = 600;
- }
- break;
- }
- this.rootView.Frame = new System.Drawing.RectangleF(x, y, width, height);
- this.mainAd.Frame = new System.Drawing.RectangleF(adX, adY, this.mainAd.Frame.Width, this.mainAd.Frame.Height);
- this.View.Frame = new System.Drawing.RectangleF(x, y, width, height);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement