iOS : ModalView with background transparent?

前端 未结 6 926
慢半拍i
慢半拍i 2020-12-24 02:14

I want to show a modalview on a viewController. (which has a naviguation controller).

On my view i have text, and a button to show the modalview.

I created

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-24 02:43

    Use following snippet to do it on iOS 8 onwards:

    For Objective C:

    UIViewController *walkThru = [self.storyboard   instantiateViewControllerWithIdentifier:@"WalkThroughScene"];
    walkThru.providesPresentationContextTransitionStyle = YES;
    walkThru.definesPresentationContext = YES;
    [walkThru setModalPresentationStyle:UIModalPresentationOverCurrentContext];
    [self.navigationController presentViewController:walkThru animated:YES completion:nil];
    

    For Swift 2 :

    let viewController : XYZViewController =     self.storyboard!.instantiateViewControllerWithIdentifier(“XYZIdentifier”) as! XYZViewController
    viewController.providesPresentationContextTransitionStyle = true
    viewController.definesPresentationContext = true
    viewController.modalPresentationStyle=UIModalPresentationStyle.OverCurrentContext
    self.presentViewController(viewController, animated: true, completion: nil)
    

    For Swift 4 :

    let viewController =  self.storyboard!.instantiateViewController(withIdentifier:  "XYZIdentifier") as! XYZViewController
    viewController.providesPresentationContextTransitionStyle = true
    viewController.definesPresentationContext = true
    viewController.modalPresentationStyle = .overCurrentContext
    self.present(viewController, animated: true, completion: nil)
    

    And the backgroundcolor of your presented viewController should be clearColor.

提交回复
热议问题