Programing

투명한 배경이있는 Swift Modal View Controller

lottogame 2020. 8. 24. 20:52
반응형

투명한 배경이있는 Swift Modal View Controller


이 질문에 이미 답변이 있습니다.

나는이 주제가 꽤 인기가 있다는 것을 알고 있지만, 프로그래밍 언어에서 약간의 문제가있다. 사실 나는 여전히 내가 코드를 어디에 두 었는지 이해하지 못한다. 글쎄, 나는 전체 사건을 말할 것이다.

여기에 이미지 설명 입력

I'm trying to make a modal Swift in a little different from normal: By clicking on a button, the ViewController is displayed (following modal type) on the screen, but with transparent background. Only the blue View with label will be displayed. When this ViewController is presented, it is with transparent background, but as soon as it completes the transition, it will stay with the black background. Already deactivated the opaque option, and tested some options, but nothing this troubleshooting.

Some can help me?

The video is a test in the simulator on the case (https://www.youtube.com/watch?v=wT8Uwmq9yqY).

I'm starting with swift, and I'm still pretty lost with how to program in Xcode, I read an answer to a question that has the following code to solve this:

self.presentingViewController.providesPresentationContextTransitionStyle = YES;
self.presentingViewController.definesPresentationContext = YES;
modal.modalPresentationStyle = UIModalPresentationOverCurrentContext;

Where do I put this code?


You can do it like this:

메인 뷰 컨트롤러에서 :

func showModal() {
    let modalViewController = ModalViewController()
    modalViewController.modalPresentationStyle = .overCurrentContext
    presentViewController(modalViewController, animated: true, completion: nil)
}

모달보기 컨트롤러에서 :

class ModalViewController: UIViewController {
    override func viewDidLoad() {
        view.backgroundColor = UIColor.clearColor()
        view.opaque = false
    }
}

스토리 보드로 작업하는 경우 :

모달 뷰 컨트롤러에 Kind설정된 Storyboard Segue를 추가 Present Modally하고이 뷰 컨트롤러에서 다음 값을 설정하면됩니다.

  • 배경 = 선명한 색상
  • Drawing = 불투명 확인란 선택 취소
  • 프레젠테이션 = 현재 컨텍스트에 대해

으로 Crashalot이 자신의 의견에서 지적 : 있는지 확인 SEGUE는 단지 사용하는 Default모두 PresentationTransition. 사용 Current Context을 위해 Presentation만드는 모달 차례 블랙을 대신 투명 남아.

참고 URL : https://stackoverflow.com/questions/33104743/swift-modal-view-controller-with-transparent-background

반응형