[iphone] UIViewController 위에 clearColor UIViewController 표시

나는이 UIViewController같은 전망을 하위 뷰 / 모달 위에 다른 UIViewController뷰, 같은과 서브 뷰 / 모달 투명해야하고 어떤 구성 요소가 표시되어야 하위 뷰에 추가됩니다. 문제는 내가 가지고있는 하위 뷰가 clearColor를 가지기 위해 검은 색 배경을 표시한다는 것입니다. UIView검은 색이 아닌 clearColor 로 만들려고합니다 . 아무도 무엇이 잘못되었는지 알고 있습니까? 모든 제안에 감사드립니다.

FirstViewController.m

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];

[vc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentModalViewController:vc animated:NO];  

SecondViewController.m

- (void)viewDidLoad
{
     [super viewDidLoad];
     self.view.opaque = YES;
     self.view.backgroundColor = [UIColor clearColor];
}

해결 : 문제를 해결했습니다. iPhone과 iPad 모두에서 잘 작동합니다. 검정색 배경이없는 모달 뷰 컨트롤러는 clearColor / transparent입니다. 내가 변경해야 할 유일한 것은로 교체 한 UIModalPresentationFullScreenUIModalPresentationCurrentContext입니다. 얼마나 간단합니다!

FirstViewController.m

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
vc.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:vc animated:NO completion:nil];

주의 사항 :modalPresentationStyle 속성을 사용하는 경우 navigationController:

FirstViewController.m

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
vc.view.backgroundColor = [UIColor clearColor];
self.navigationController.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:vc animated:NO completion:nil];

주의 사항 : 나쁜 소식은 위의 솔루션이 iOS 7에서 작동하지 않는다는 것입니다. 좋은 소식은 iOS7의 문제를 해결했다는 것입니다! 나는 누군가에게 도움을 요청했고 여기에 그가 말한 것이 있습니다.

보기 컨트롤러를 모달로 표시 할 때 iOS는 표시되는 기간 동안보기 계층에서보기 컨트롤러를 제거합니다. 모달 표시 뷰 컨트롤러의 뷰는 투명하지만 그 아래에는 앱 창 (검은 색) 외에는 아무것도 없습니다. iOS 7은 새로운 모달 프레젠테이션 스타일을 도입하여 UIModalPresentationCustomiOS가 제시된 뷰 컨트롤러 아래의 뷰를 제거하지 못하게합니다. 그러나이 모달 프레젠테이션 스타일을 사용하려면 프레젠테이션을 처리하고 애니메이션을 해제 할 고유 한 전환 대리자를 제공해야합니다. 이 내용은 WWDC 2013 https://developer.apple.com/wwdc/videos/?id=218의 ‘View Controller를 사용한 사용자 정의 전환’대화에 요약되어 있으며, 자신의 전환 위임을 구현하는 방법도 다룹니다.

iOS7에서 위 문제에 대한 내 솔루션을 볼 수 있습니다 : https://github.com/hightech/iOS-7-Custom-ModalViewController-Transitions



답변

iOS8 이상

iOS8 이상에서는 새로운 modalPresentationStyle UIModalPresentationOverCurrentContext를 사용하여 투명한 배경의 뷰 컨트롤러를 제공 할 수 있습니다.

MyModalViewController *modalViewController = [[MyModalViewController alloc] init];
modalViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:modalViewController animated:YES completion:nil];    


답변

해결 : 문제를 해결했습니다. iPhone과 iPad 모두에서 잘 작동합니다. 검정색 배경이없는 모달 뷰 컨트롤러는 clearColor / transparent입니다. 변경해야 할 유일한 것은 UIModalPresentationFullScreen을 UIModalPresentationCurrentContext로 바꾼 것입니다. 얼마나 간단합니다!

FirstViewController.m

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
    vc.view.backgroundColor = [UIColor clearColor];
    self.modalPresentationStyle = UIModalPresentationCurrentContext;
    [self presentViewController:vc animated:NO completion:nil];

주의 사항 : navigationController의 modalPresentationStyle 특성을 사용하는 경우 :

FirstViewController.m

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
    vc.view.backgroundColor = [UIColor clearColor];
    self.navigationController.modalPresentationStyle = UIModalPresentationCurrentContext;
    [self presentViewController:vc animated:NO completion:nil];

주의 사항 : 나쁜 소식은 위의 솔루션이 iOS 7에서 작동하지 않는다는 것입니다. 좋은 소식은 iOS7의 문제를 해결했다는 것입니다! 나는 누군가에게 도움을 요청했고 여기에 그가 말한 것이 있습니다.

보기 컨트롤러를 모달로 표시 할 때 iOS는 표시되는 기간 동안보기 계층에서보기 컨트롤러를 제거합니다. 모달 표시 뷰 컨트롤러의 뷰는 투명하지만 그 아래에는 앱 창 (검은 색) 외에는 아무것도 없습니다. iOS 7은 새로운 모달 프레젠테이션 스타일 인 UIModalPresentationCustom을 도입하여 iOS가 제시된 뷰 컨트롤러 아래의 뷰를 제거하지 못하게합니다. 그러나이 모달 프레젠테이션 스타일을 사용하려면 프레젠테이션을 처리하고 애니메이션을 해제 할 고유 한 전환 대리자를 제공해야합니다. 이 내용은 WWDC 2013 https://developer.apple.com/wwdc/videos/?id=218의 ‘View Controller를 사용한 사용자 정의 전환’대화에 요약되어 있으며, 자신의 전환 위임을 구현하는 방법도 다룹니다.

iOS7에서 위 문제에 대한 내 솔루션을 볼 수 있습니다 : https://github.com/hightech/iOS-7-Custom-ModalViewController-Transitions


답변

따라서 순수하게 시각적 인 사고 자와 스토리 보드 팬을 위해 다음을 수행 할 수 있습니다.

1. 뷰 컨트롤러 제시

컨텍스트 정의

2. 제시된 뷰 컨트롤러

프리젠 테이션 : 과전류 컨텍스트


답변

스위프트 3 및 iOS10 솔루션 :

//create view controller
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "RoadTripPreviewViewController")
//remove black screen in background
vc.modalPresentationStyle = .overCurrentContext
//add clear color background
vc.view.backgroundColor = UIColor.clear
//present modal
self.present(vc, animated: true, completion: nil)


답변

이것은 컨트롤 드래그 세구를 사용하는 xCode 7 베타 4에서 가져온 것입니다. 목적지의 배경을 깨끗하게 설정하고 IB에서 segue 속성을 다음과 같이 설정하십시오 (참조 : 프레젠테이션은 “전체 화면 오버”).

여기에 이미지 설명을 입력하십시오


답변

iOS7 및 iOS8에서 작동하는 가장 쉬운 방법은 iOS8 때문에 modallyPresentedVC (모달로 표시하려는 ViewController)의 presentationStyle을 UIModalPresentationOverCurrentContext에 추가하는 것입니다.

[modallyPresentedVC setModalPresentationStyle:UIModalPresentationOverCurrentContext];
[modallyPresentedVC.navigationController setModalPresentationStyle:UIModalPresentationOverCurrentContext];

iOS7로 인해 VC (모달로 제시된 컨트롤러)를 제공하는 UIModalPresentationCurrentContext :

[presentingVC setModalPresentationStyle:UIModalPresentationCurrentContext];
[presentingVC.navigationController setModalPresentationStyle:UIModalPresentationCurrentContext];

iOS7과 iOS8에서는 상황이 다르게 처리되기 때문입니다. 물론 navigationController 속성을 사용하지 않으면 설정할 필요가 없습니다. 희망이 도움이됩니다.


답변

스위프트 2 버전 :

let vc = self.storyboard!.instantiateViewControllerWithIdentifier("YourViewController") as! YourViewController
vc.view.backgroundColor = UIColor.clearColor()
vc.modalPresentationStyle = UIModalPresentationStyle.OverFullScreen // orOverCurrentContext to place under navigation
self.presentViewController(vc, animated: true, completion: nil)