web-dev-qa-db-ja.com

ModalViewController透明背景iOS 8

Xcode 6で古いプロジェクトを開き、表示されたビューコントローラーで背景が透明でないという問題を発見しました。以下のトピックでソリューションを使用しましたが、これまでのところios7で機能しました。 iOS:背景が透明なModalView?

IOS 8への対処方法をアドバイスしてください。

19
Madman

presentedビューコントローラのmodalPresentationStyleプロパティを新しいUIModalPresentationOverCurrentContext定数に設定してみてください。

[_modalViewController setModalPresentationStyle:UIModalPresentationOverCurrentContext]
47
mmccomb

mmccombのソリューションは最終的にはうまくいきましたが、いくつかのことを調整する必要がありました。うまくいけば、これらの詳細が誰かを助ける:

1)私は次のように、表示されたビューコントローラーから表示されたビューコントローラーのプロパティを設定する必要がありました。

MyViewController *myVc = [segue destinationViewController];
[myVc setModalPresentationStyle:UIModalPresentationOverCurrentContext];

提示されたVCのviewDidLoad内からの提示スタイルの設定が機能しませんでした。

2)ストーリーボードを使用していて、セグエプロパティに移動して、プレゼンテーションスタイルをデフォルトに設定する必要がありました。他の値を設定すると、背景が黒くなります。

19
itnAAnti

Interface Builderソリューション

@mmccombのプログラムによるソリューションに感謝します。

これを達成するには:

  1. セグエの作成ストーリーボードファイル内(Ctrl +クリック&ドラッグ)

  2. ドロップダウンオプションからPresent Modallyを選択する

  3. IBストーリーボードでモーダルセグエを選択-(セグエのみ)

  4. Attributes InspectorPresentationOver Current Contextに設定します

アルファ/不透明度を50%+に変更し、より暗い背景色を使用することをお勧めします。そうしないと、表示しているビューコントローラのコンテンツとモーダルで表示しているコンテンツを区別するのが難しくなります。

17
ChrisHaze

「segue」でプレゼンテーションスタイルを変更した場合は、デフォルトに戻す必要があります。またはそれはあなたに黒い背景を与えます。

StoryboardをSegue configで使用してみましたが、機能しません。

これが- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)senderメソッドで機能するコードです:

// Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:@"PresentStationChooserViewController"])
{
    ChooseStationViewController *controller = [segue destinationViewController];
    controller.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7f];
    [controller setModalPresentationStyle:UIModalPresentationOverCurrentContext];
    controller.stationList = _remoteStations;
}
4
c9s

iOS8 +

以下のコードスニペットを見てください、それは私の問題を解決しました、

SecondViewController *secondViewController = [[SecondViewController alloc] init];
secondViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;           
[self presentViewController:secondViewController animated:YES completion:nil];    
0
arunjos007