presentViewController black background instead of transparent

后端 未结 5 876
栀梦
栀梦 2021-01-18 03:24

I have a view that I wish to present to the user in the standard way (sliding up from the bottom of the screen). About half this view is a transparent background and the bot

5条回答
  •  -上瘾入骨i
    2021-01-18 04:08

    This is possible, and rockybalboa provides a solution to this issue in the forum post on raywenderlich.com:

    iOS 8 UIModalPresentationCurrentContext is not transparent?

    That solution being, quoting balboa's answer, in Objective-C:

    Before iOS 8, you do this:

    [backgroundViewController setModalPresentationStyle:UIModalPresentationCurrentContext];
    [backgroundViewController presentViewController:_myMoreAppsViewController animated:NO completion:nil];
    

    in iOS 8, you have to do this:

    backgroundViewController.providesPresentationContextTransitionStyle = YES;
    backgroundController.definesPresentationContext = YES;
    [overlayViewController setModalPresentationStyle:UIModalPresentationOverCurrentContext];
    

    To supplement the above code with the Swift equivalent:

    backgroundViewController.providesPresentationContextTransitionStyle = true
    backgroundController.definesPresentationContext = true
    overlayViewController.modalPresentationStyle = .OverCurrentContext
    

    Having implemented this using Xcode 6.3 beta 3 on iOS 8.1 with Swift 1.2, it works perfectly.

    Just a comment that I viewed three different SO questions on this - the more recent now marked as duplicates - prior to finding and attempting the Ray Wenderlich forum solution.

提交回复
热议问题