代码之家  ›  专栏  ›  技术社区  ›  user2074945

iOS TabbarController覆盖内容

  •  1
  • user2074945  · 技术社区  · 6 年前

    我有一个TabBarController,可以显示不同的页面。问题是,页面底部的选项卡栏并没有限制选项卡内内容的大小,而是覆盖了它。有没有办法改变这种行为。更多信息:

    • 我用沙马林。iOS但要启动TabBarController(带有情节提要),但选项卡的内容是Xamarin Forms ContentPages。(天然Xamarin形式)
    • 这是我的问题图片

    enter image description here

    编辑1 以下是我用来初始化XF ContentPage的代码:

    namespace Happimeter.iOS
    {
        public partial class SurveyViewController : UINavigationController
        {
            public SurveyViewController (IntPtr handle) : base (handle)
            {
                //InitializeSurveyView is a XF ContentPage
                var formsPage = new InitializeSurveyView();
                var startSurveyVc = formsPage.CreateViewController();
                PushViewController(startSurveyVc, true);
                startSurveyVc.Title = formsPage.Title;
    
                //some code omitted for brevity
    
                NavigationBar.TintColor = UIColor.White;
            }
        }
    }
    

    我将viewController分配给情节提要中的tabBarController。见下文:

    主要的情节提要:

    <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="49e-Tb-3d3" useSafeAreas="YES">
    <device id="retina4_7" orientation="portrait">
        <adaptation id="fullscreen"/>
    </device>
    <dependencies>
        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
        <capability name="Constraints to layout margins" minToolsVersion="6.0"/>
        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
        <capability name="Safe area layout guides" minToolsVersion="9.0"/>
    </dependencies>
    <customFonts key="customFonts">
        <array key="HelveticaNeue.ttc">
            <string>HelveticaNeue</string>
        </array>
    </customFonts>
    <scenes>
        <!--About-->
        <!--Tab Bar Controller-->
        <scene sceneID="yl2-sM-qoP">
            <objects>
                <tabBarController storyboardIdentifier="tabViewController" id="49e-Tb-3d3" customClass="TabBarController" sceneMemberID="viewController">
                    <nil key="simulatedBottomBarMetrics"/>
                    <tabBar key="tabBar" contentMode="scaleToFill" id="W28-zg-YXA" clipsSubviews="YES">
                        <rect key="frame" x="0.0" y="618" width="375" height="49"/>
                        <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
                        <color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
                    </tabBar>
                    <connections>
                        <segue id="83046" destination="82960" kind="relationship" relationship="viewControllers"/>
                        <segue id="91417" destination="91401" kind="relationship" relationship="viewControllers"/>
                        <segue id="96651" destination="96631" kind="relationship" relationship="viewControllers"/>
                        <segue id="100501" destination="95834" kind="relationship" relationship="viewControllers"/>
                    </connections>
                </tabBarController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="HuB-VB-40B" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="0.0" y="0.0"/>
        </scene>
        <!--Browse-->
        <!--About-->
        <!--Items-->
        <!--Title-->
        <!--New Item-->
        <!--Login View Controller-->
        <!--Login View Controller-->
        <!--Login View Controller-->
        <!--View Controller-->
        <scene sceneID="82959">
            <objects>
                <navigationController id="82960" sceneMemberID="viewController" customClass="SurveyViewController">
                    <navigationBar key="navigationBar" contentMode="scaleToFill" id="82962" translucent="NO">
                        <rect key="frame" x="0.0" y="20" width="375" height="44"/>
                        <autoresizingMask key="autoresizingMask"/>
                        <color key="barTintColor" colorSpace="calibratedRGB" red="0.18823529411764706" green="0.47843137254901963" blue="0.91764705882352937" alpha="1"/>
                        <textAttributes key="titleTextAttributes">
                            <color key="textColor" colorSpace="calibratedWhite" white="1" alpha="1"/>
                        </textAttributes>
                    </navigationBar>
                    <connections/>
                    <tabBarItem key="tabBarItem" title="Item" id="83045"/>
                    <simulatedTabBarMetrics key="simulatedBottomBarMetrics"/>
                </navigationController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="82963" userLabel="First Responder" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="-495" y="794"/>
        </scene>
        <scene sceneID="91400">
            <objects>
                <navigationController id="91401" sceneMemberID="viewController" customClass="MoodOverviewViewController">
                    <navigationBar key="navigationBar" contentMode="scaleToFill" id="91403" translucent="NO">
                        <rect key="frame" x="0.0" y="20" width="375" height="44"/>
                        <autoresizingMask key="autoresizingMask"/>
                        <color key="barTintColor" colorSpace="calibratedRGB" red="0.18823529411764706" green="0.47843137254901963" blue="0.91764705882352937" alpha="1"/>
                        <textAttributes key="titleTextAttributes">
                            <color key="textColor" colorSpace="calibratedWhite" white="1" alpha="1"/>
                        </textAttributes>
                    </navigationBar>
                    <connections/>
                    <tabBarItem key="tabBarItem" title="Item" id="91402"/>
                    <simulatedTabBarMetrics key="simulatedBottomBarMetrics"/>
                </navigationController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="91404" userLabel="First Responder" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="726" y="-1558"/>
        </scene>
        <scene sceneID="95833">
            <objects>
                <navigationController id="95834" sceneMemberID="viewController" customClass="SettingsPageViewController">
                    <navigationBar key="navigationBar" contentMode="scaleToFill" id="95836" translucent="NO">
                        <rect key="frame" x="0.0" y="20" width="375" height="44"/>
                        <autoresizingMask key="autoresizingMask"/>
                        <color key="barTintColor" colorSpace="calibratedRGB" red="0.18823529411764706" green="0.47843137254901963" blue="0.91764705882352937" alpha="1"/>
                        <textAttributes key="titleTextAttributes">
                            <color key="textColor" colorSpace="calibratedWhite" white="1" alpha="1"/>
                        </textAttributes>
                    </navigationBar>
                    <connections/>
                    <tabBarItem key="tabBarItem" title="Item" id="95835"/>
                    <simulatedTabBarMetrics key="simulatedBottomBarMetrics"/>
                </navigationController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="95837" userLabel="First Responder" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="959" y="-809"/>
        </scene>
        <scene sceneID="96630">
            <objects>
                <navigationController id="96631" sceneMemberID="viewController" customClass="BluetoothPageViewController">
                    <navigationBar key="navigationBar" contentMode="scaleToFill" id="96633" translucent="NO">
                        <rect key="frame" x="0.0" y="20" width="375" height="44"/>
                        <autoresizingMask key="autoresizingMask"/>
                        <color key="barTintColor" colorSpace="calibratedRGB" red="0.18823529411764706" green="0.47843137254901963" blue="0.91764705882352937" alpha="1"/>
                        <textAttributes key="titleTextAttributes">
                            <color key="textColor" colorSpace="calibratedWhite" white="1" alpha="1"/>
                        </textAttributes>
                    </navigationBar>
                    <connections/>
                    <tabBarItem key="tabBarItem" title="Item" id="96632"/>
                    <simulatedTabBarMetrics key="simulatedBottomBarMetrics"/>
                </navigationController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="96634" userLabel="First Responder" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="1350" y="-809"/>
        </scene>
        <scene sceneID="97944">
            <objects>
                <navigationController id="97945" sceneMemberID="viewController" customClass="SignInViewController" storyboardIdentifier="SignInViewController">
                    <navigationBar key="navigationBar" contentMode="scaleToFill" id="97947" translucent="NO">
                        <rect key="frame" x="0.0" y="20" width="375" height="44"/>
                        <autoresizingMask key="autoresizingMask"/>
                        <color key="barTintColor" colorSpace="calibratedRGB" red="0.18823529411764706" green="0.47843137254901963" blue="0.91764705882352937" alpha="1"/>
                        <textAttributes key="titleTextAttributes">
                            <color key="textColor" colorSpace="calibratedWhite" white="1" alpha="1"/>
                        </textAttributes>
                    </navigationBar>
                    <connections/>
                    <tabBarItem key="tabBarItem" title="Item" id="97946"/>
                    <simulatedTabBarMetrics key="simulatedBottomBarMetrics"/>
                </navigationController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="97948" userLabel="First Responder" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="2905" y="-16"/>
        </scene>
    </scenes>
    <resources>
        <image name="First" width="32" height="30"/>
        <image name="HappimeterLogo" width="261" height="48"/>
        <image name="Second" width="32" height="30"/>
        <image name="XamarinLogo" width="220" height="51"/>
        <image name="happinessfactory" width="202" height="114"/>
    </resources>
    

    2 回复  |  直到 6 年前
        1
  •  0
  •   user2074945    6 年前
    public partial class TabBarController : UITabBarController
    {
        public TabBarController(IntPtr handle) : base(handle)
        {
            //this does the trick!
            TabBar.Translucent = false;
        }
    }
    
        2
  •  0
  •   Roman    4 年前

    这对我很有用:

    class TabBarController: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        tabBar.isTranslucent = false
    }