2012-02-21 47 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

相关问题