【问题标题】:monotouch rotate in landscapemode and portrait modemonotouch 在横向模式和纵向模式下旋转
【发布时间】:2012-02-21 11:36:32
【问题描述】:

我是 iPad 开发人员的新手,

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

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

其中,我想在orientation 中移动我的tableView,

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

详情请看我的屏幕截图...

在第一张图片(纵向模式)中,我的桌子在extremeLeft,在第二张图片(横向模式)中,我希望我的桌子在最右边..

我该怎么做?

我以编程方式创建了 tableview,这里是代码 sn-p,

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

我们将不胜感激。

提前致谢!

【问题讨论】:

  • 我认为你应该通过 Montouch 教程 (ios.xamarin.com/Tutorials),如果你知道如何在 ObjC 中解决问题,你应该能够轻松地将它们翻译成 C#/Monotouch。跨度>

标签: iphone ipad uitableview xamarin.ios orientation


【解决方案1】:

您可以覆盖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);
    }

【讨论】:

  • 老兄,我想在我的 ViewDidLoad() 方法中调用这个方法,我应该如何调用它?
  • 您可以在 ViewDidLoad 中复制相同的代码 (switch) 并调用 base.ViewDidLoad... 但是当您旋转设备时不会调用此代码(因此您的对齐调整不会除非设备在在加载之前旋转)。
  • 不要把代码复制过来,自己调用传参的方法:WillRotate(InterfaceOrientation, 0);
猜你喜欢
  • 1970-01-01
  • 2012-11-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-10
  • 1970-01-01
相关资源
最近更新 更多