2012-02-21 97 views
2

我是新來iPad開發商,MonoTouch的旋轉landscapemode和肖像模式

我已創建使用Xcode 4.

目標C兩個或三個iPad應用程序,但現在我想創建使用Monodeveloper工具iPad應用C#語言...

在其中,我想我的tableView轉變orientation

我在谷歌搜索,但我沒有任何語法。

查看詳細見我的屏幕截圖...

在第一圖像(肖像模式)我的表是extremeLeft,在第二圖像(風景模式),我想我的表是在最右邊..

screenshot 我應該怎麼做?

我創建的tableview編程,這裏是代碼片段,

public override void ViewDidLoad() 
     { 
      base.ViewDidLoad(); 
      Gainer(); //method call 
       UITableView Table=new UITableView(); 
      Table.Frame=new RectangleF(20,200,400,400); 
      Table.Source=new TableViewDataSource(TopGainer); //passing parameter to tableview datasource 
      this.View.AddSubview(Table); 


     } 

public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation) 
     { 
      // Return true for supported orientations 
      return true; 
     } 

任何幫助將不勝感激。

在此先感謝!

+0

我認爲你應該通過Montouch教程(http://ios.xamarin.com/Tutorials),如果你知道如何解決ObjC中的事情,你應該很容易能夠將它們翻譯成C#/ MonoTouch的。 – Krumelur 2012-02-21 18:48:29

回答

2

您可以覆蓋WillRotate方法並根據UIScreen.MainScreen提供的值,在每種情況下應用所需的確切位置。例如。

public override void WillRotate (UIInterfaceOrientation toInterfaceOrientation, double duration) 
    { 
     switch (toInterfaceOrientation) { 
     case UIInterfaceOrientation.LandscapeLeft: 
     case UIInterfaceOrientation.LandscapeRight: 
      Table.Frame = new RectangleF (UIScreen.MainScreen.Bounds.Width - 20 - Table.Frame.Width, 200, 400, 400); 
      break; 
     case UIInterfaceOrientation.Portrait: 
     case UIInterfaceOrientation.PortraitUpsideDown: 
      Table.Frame = new RectangleF (20, 200, 400, 400); 
      break; 
     } 
     base.WillRotate (toInterfaceOrientation, duration); 
    } 
+0

老兄,我想在我的ViewDidLoad()方法中調用這個方法,我應該如何調用它? – Krunal 2012-02-22 05:48:45

+0

你可以在你的'ViewDidLoad'中拷貝相同的代碼('switch')並調用'base.ViewDidLoad ...'但是當你旋轉設備時不會調用它(所以你的對齊調整將不起作用該設備在*被加載之前旋轉*)。 – poupou 2012-02-22 13:03:22

+0

不要複製代碼,只需調用自己傳遞參數的方法:WillRotate(InterfaceOrientation,0); – PmanAce 2015-10-05 17:38:16