Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.35 KB | None | 0 0
  1. using System;
  2. using MonoTouch.Dialog;
  3. using MonoTouch.UIKit;
  4. using MonoTouch;
  5. using MonoTouch.Foundation;
  6. using MonoTouch.ObjCRuntime;
  7.  
  8. namespace SMSMaster
  9. {
  10.     public partial class mainController : UIViewController
  11.     {
  12.         private NSObject notificationObserver;
  13.        
  14.         public mainController ()
  15.         {  
  16.         }
  17.        
  18.         public mainController (IntPtr p) : base(p)
  19.         {
  20.         }
  21.        
  22.         public override void ViewWillAppear (bool animated)
  23.         {
  24.            
  25.         }
  26.        
  27.         public override void ViewDidLoad ()
  28.         {
  29.             notificationObserver = NSNotificationCenter.DefaultCenter.AddObserver("UIDeviceOrientationDidChangeNotification", DeviceRotated ); 
  30.         }
  31.        
  32.         public override void ViewDidAppear (bool animated)
  33.         {
  34.             UIDevice.CurrentDevice.BeginGeneratingDeviceOrientationNotifications();
  35.         }
  36.        
  37.         public override void ViewWillDisappear (bool animated)
  38.         {
  39.             UIDevice.CurrentDevice.EndGeneratingDeviceOrientationNotifications();
  40.         }
  41.        
  42.         public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation)
  43.         {
  44.             return true;
  45.         }
  46.        
  47.         private void DeviceRotated(NSNotification notification){
  48.            
  49.             reloadView();
  50.            
  51.         }
  52.        
  53.         private void reloadView()
  54.         {
  55.             float x = 0;
  56.             float y = 0;
  57.             float height = 0;
  58.             float width = 0;
  59.             float adX = 0;
  60.             float adY = 0;
  61.            
  62.             switch(UIDevice.CurrentDevice.Orientation)
  63.             {
  64.             case UIDeviceOrientation.LandscapeLeft:
  65.             case UIDeviceOrientation.LandscapeRight:
  66.                 x = 0;
  67.                 y = 300;
  68.                 adX = 0;
  69.                 adY = 690;
  70.                 height = 650;
  71.                 width = 704;
  72.                 break;
  73.                
  74.             case UIDeviceOrientation.Portrait:
  75.             case UIDeviceOrientation.PortraitUpsideDown:
  76.                 x = 0;
  77.                 y = 0;
  78.                 adX = 0;
  79.                 adY = 690;
  80.                 height = 500;
  81.                 width = 600;
  82.                 break;
  83.                
  84.             default:
  85.                 if(Application.window.Frame.Width > Application.window.Frame.Height)
  86.                 {
  87.                     x = 0;
  88.                     y = 300;
  89.                     adX = 0;
  90.                     adY = 690;
  91.                     height = 650;
  92.                     width = 704;
  93.                 }
  94.                 else
  95.                 {
  96.                     x = 0;
  97.                     y = 0;
  98.                     adX = 0;
  99.                     adY = 960;
  100.                     height = 500;
  101.                     width = 600;
  102.                 }
  103.                 break;
  104.                
  105.             }
  106.            
  107.             this.rootView.Frame = new System.Drawing.RectangleF(x, y, width, height);
  108.             this.mainAd.Frame = new System.Drawing.RectangleF(adX, adY, this.mainAd.Frame.Width, this.mainAd.Frame.Height);
  109.             this.View.Frame = new System.Drawing.RectangleF(x, y, width, height);
  110.         }
  111.        
  112.     }
  113.    
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement