monotouch在landscapemode和portrait模式下旋转

时间:2012-02-21 11:36:32

标签: iphone ipad uitableview xamarin.ios orientation

我是iPad开发人员的新手,

我使用iPad

在目标c中创建了两个或三个Xcode 4.应用程序

但现在我想使用iPad语言中的Monodeveloper工具创建C#应用程序......

其中,我想在orientation

中移动我的tableView

我在谷歌搜索但我没有任何语法。

有关详细信息,请参阅我的屏幕截图...

在第一张图片(肖像模式)中,我的桌子位于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;
        }

我们将不胜感激。

提前致谢!!

1 个答案:

答案 0 :(得分:2)

您可以覆盖WillRotate方法,并根据UIScreen.MainScreen提供的值,在每种情况下应用您想要的确切位置。 E.g。

    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);
    }