ios 自定义 Push Segue 删除故事板中的导航栏和标签栏

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20058701/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 22:25:45  来源:igfitidea点击:

Custom Push Segue removes navigation bar and tab bar in story board

ioscocoa-touchios7segueuistoryboardsegue

提问by www.jensolsson.se

I have the following defined in a custom Segue, let us call it SegueX:

我在自定义 Segue 中定义了以下内容,我们称之为 SegueX:

@interface SegueX : UIStoryboardSegue
@end

@implementation SegueX

- (void)perform
{
    CATransition* transition = [CATransition animation];

    transition.duration = 0.3;
    transition.type = kCATransitionFade;

    [[self.sourceViewController navigationController].view.layer addAnimation:transition forKey:kCATransition];
    [[self.sourceViewController navigationController] pushViewController:[self destinationViewController] animated:NO];
}

@end

In my story board I have just changed a standard Push segue to SegueX. For some reason this will remove my navigation bar and tab bar. Furthermore all UIBarButtonItems I have defined in the story board after the custom segue are hidden at runtime. How do I fix this? I hope it is not meant to be this way...

在我的故事板中,我刚刚将标准 Push segue 更改为 SegueX。出于某种原因,这将删除我的导航栏和标签栏。此外,在自定义转场之后,我在故事板中定义的所有 UIBarButtonItems 都在运行时隐藏。我该如何解决?我希望它不是这样的......

Before changing to a custom segue

在更改为自定义 segue 之前

Before changing to a custom segue

在更改为自定义 segue 之前

After changing to a custom segue

更改为自定义 segue 后

After changing to a custom segue

更改为自定义 segue 后

enter image description here

enter image description here

Save this to Main.storyboard

将此保存到 Main.storyboard

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="4514" systemVersion="13A603" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="aUj-3O-DdX">
    <dependencies>
        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3747"/>
    </dependencies>
    <scenes>
        <!--Navigation Controller-->
        <scene sceneID="prC-ky-DMz">
            <objects>
                <navigationController definesPresentationContext="YES" id="aUj-3O-DdX" sceneMemberID="viewController">
                    <navigationBar key="navigationBar" contentMode="scaleToFill" id="2Uu-Rm-RXH">
                        <autoresizingMask key="autoresizingMask"/>
                    </navigationBar>
                    <toolbar key="toolbar" opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="aOK-Kc-Mfz">
                        <rect key="frame" x="0.0" y="416" width="320" height="44"/>
                        <autoresizingMask key="autoresizingMask"/>
                    </toolbar>
                    <connections>
                        <segue destination="PDT-yG-B9z" kind="relationship" relationship="rootViewController" id="w27-w2-lcd"/>
                    </connections>
                </navigationController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="fNx-r3-Dzg" userLabel="First Responder" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="-65" y="-179"/>
        </scene>
        <!--View Controller-->
        <scene sceneID="kMj-Al-ZjY">
            <objects>
                <viewController id="PDT-yG-B9z" sceneMemberID="viewController">
                    <layoutGuides>
                        <viewControllerLayoutGuide type="top" id="RKt-BS-gn9"/>
                        <viewControllerLayoutGuide type="bottom" id="eFe-fv-bG6"/>
                    </layoutGuides>
                    <view key="view" contentMode="scaleToFill" id="JbT-x8-qhX">
                        <rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
                        <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                        <subviews>
                            <button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="fTw-C6-P3N">
                                <rect key="frame" x="137" y="269" width="46" height="30"/>
                                <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                <state key="normal" title="Button">
                                    <color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
                                </state>
                                <connections>
                                    <segue destination="uMi-ds-4FY" kind="custom" id="mPL-yx-hFQ"/>
                                </connections>
                            </button>
                        </subviews>
                        <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
                    </view>
                    <navigationItem key="navigationItem" id="Im9-4G-4Ga"/>
                </viewController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="qXF-QN-k3Z" userLabel="First Responder" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="473" y="-177"/>
        </scene>
        <!--View Controller-->
        <scene sceneID="ca6-vg-B3h">
            <objects>
                <viewController id="uMi-ds-4FY" sceneMemberID="viewController">
                    <layoutGuides>
                        <viewControllerLayoutGuide type="top" id="jd0-A9-WOV"/>
                        <viewControllerLayoutGuide type="bottom" id="5VJ-sS-U1V"/>
                    </layoutGuides>
                    <view key="view" contentMode="scaleToFill" id="gJp-P2-rUC">
                        <rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
                        <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                        <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
                    </view>
                </viewController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="pih-Kj-ioJ" userLabel="First Responder" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="1003" y="-179"/>
        </scene>
    </scenes>
    <simulatedMetricsContainer key="defaultSimulatedMetrics">
        <simulatedStatusBarMetrics key="statusBar"/>
        <simulatedOrientationMetrics key="orientation"/>
        <simulatedScreenMetrics key="destination" type="retina4"/>
    </simulatedMetricsContainer>
</document>

采纳答案by rdelmar

The navigation bar and the tool bar should disappear in the storyboard when you change the segue -- that's normal. You can change the simulated metrics for the bottom bar to "Translucent Toolbar", which will add it back, so you can add buttons to it (you only want to change the simulated metrics, not drag in another tool bar which would add a second tool bar). You should still see both bars with their buttons at run time.

当您更改 segue 时,导航栏和工具栏应该在情节提要中消失——这是正常的。您可以将底部栏的模拟指标更改为“半透明工具栏”,这会将其添加回来,因此您可以向其添加按钮(您只想更改模拟指标,而不是拖入另一个会添加第二个工具栏的工具栏)工具栏)。在运行时,您仍然应该看到带有按钮的两个条。

回答by Andrea

Try to check if you have set on storyboard an option like
enter image description here
That metrics are inferred on the pushed view controller (but I'm pretty sure it doesn't count).
enter image description here

尝试检查您是否在情节提要上设置了一个选项,例如
enter image description here
在推送的视图控制器上推断出指标(但我很确定它不算数)。
enter image description here

And/or force the navigation bar and bottom bar to be visible programmatically using, inside the -viewWillAppearof the pushed view controller

和/或强制导航栏和底部栏以编程方式使用,在-viewWillAppear推送的视图控制器内部可见

[self.navigationController setNavigationBarHidden:NO animated:NO];
[self.navigationController setToolbarHidden:NO animated:NO];

回答by SuvaP

(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    ViewController * controller = [[ViewController alloc]init];
    controller.hidesBottomBarWhenPushed=YES;
    if ([segue.identifier isEqualToString:@"Commentsegue"]) {
        //For hiding the tab bar 
        [segue.destinationViewController setHidesBottomBarWhenPushed:YES];
    } 
}