2016-07-03 39 views
0

我在Xamarin for iOS中採取了幾個第一步,並且很難弄清楚如何創建一個獨立於解決方案的視圖。解決方案在Xamarin中的獨立性iOS

我有一個單一的文本框在視圖中,對齊,使其邊緣符合iPhone 6S的邊緣。當我將視圖更改爲Iphone 4S時,文本框的邊緣位於視圖之外。

我試圖將約束拖動到邊緣,幾乎點擊每個按鈕,並試圖找到一些如何使它的示例,以便視圖調整大小以適應視口,但我不能使它工作。我也擺弄了View的不同模式(Aspect Fit,Scale to Fill等),但這並沒有什麼區別。

我很想看一個簡單的例子,說明如何創建分辨率獨立或多分辨率的窗體或視圖,無論iPhone上的屏幕分辨率如何顯示。

+0

嘗試搜索iOS Auto Layout Constraints;即http://mobileoop.com/how-to-use-auto-layout-in-xcode-6-for-ios-7-and-8-development&http://mobileoop.com/auto-layout-advanced -techniques-for-ios-8-and-7-using-xcode-6-on-storyboard ... – SushiHangover

+0

發現這個tutoriar,繼此之後,我得到了它的工作。 https://developer.xamarin.com/guides/ios/user_interface/designer/designer_auto_layout/ – JensB

回答

1

已經通過大同小異的疼痛消失了,你,我的建議是兩方面:

  1. 看一看在Cirrious FluentLayouts包,你可以從 得到的NuGet。

在簡化各種自動佈局問題方面提供了巨大的幫助,特別是如果您決定放棄GUI佈局工具並採用完整的程序化方法時(尤其是像我一樣)。

它將使同樣的結構:

this.AddConstraints 
(
    _navBar.AtTopOf(this, UIApplication.SharedApplication.StatusBarFrame.Height), 
    _navBar.AtLeftOf(this), 
    _navBar.WithSameWidth(this), 
    _navBar.Height().EqualTo(Hamburger.HamburgerHeight), 

    _scrollView.Below(_navBar), 
    _scrollView.AtLeftOf(this), 
    _scrollView.WithSameWidth(this), 
    _scrollView.Bottom().EqualTo().TopOf(_pageControl), 

    _pageControl.Above(_toolBar), 
    _pageControl.AtLeftOf(this), 
    _pageControl.WithSameWidth(this), 
    _pageControl.Height().EqualTo(pageControlHeight), 

    _toolBar.Above(_button), 
    _toolBar.AtLeftOf(this), 
    _toolBar.WithSameWidth(this), 
    _toolBar.Height().EqualTo(toolHeight), 

    _button.AtRightOf(this), 
    _button.AtBottomOf(this), 
    _button.Height().EqualTo(buttonHeight) 
); 
  • 注意,因爲...的iOS 8我相信嗎? ...您現在需要使用 LaunchScreen.xib讓您的應用程序正確地獲取設備 分辨率,然後通過自動佈局使用該分辨率。
  • 這是我仍然需要使用圖形佈局工具的一個領域 - 只有一次,很高興地說。

    相關問題