programing

UIViewController 위에 선명한 색상 UIViewController 표시

closeapi 2023. 5. 1. 21:23
반응형

UIViewController 위에 선명한 색상 UIViewController 표시

나는 있습니다UIViewController다른 것 위에 있는 하위 뷰/하위 뷰로 보기UIViewController(는: 뷰하뷰투하하/▁the뷰▁problem함▁black)(▁backview▁the뷰▁clear▁is예▁i▁showscolor▁that▁have▁sub) 문제는 서브뷰가 clearColor대신 을 보여준다는 입니다.문제는 하위 뷰에 검은색 배경이 표시되어 clearColor가 있다는 것입니다.는 내가만것은는려들것을 만들려고 합니다UIView검은색 배경이 아닌 선명한 색상으로 표시됩니다.그것에 무슨 문제가 있는지 아는 사람이 있습니까?어떤 제안이든 감사합니다.

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];
}

해결됨: 문제를 해결했습니다.그것은 아이폰과 아이패드 모두에 매우 잘 작동합니다.검은색 배경이 없는 모달 뷰 컨트롤러는 색상만 선명하고 투명합니다.내가 바꿀 필요가 있는 유일한 것은 교체하는 것입니다.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];

주의: 를 사용하는 경우modalPresentationStylenavigationController:

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는 표시되는 기간 동안 아래의 보기 컨트롤러를 보기 계층에서 제거합니다.한 뷰 하지만, 그 창, 즉 도 없습니다. 스타일을 소개했습니다.UIModalPresentationCustom이로 인해 iOS는 표시된 보기 컨트롤러 아래의 보기를 제거하지 못합니다.그러나 이 모달 프레젠테이션 스타일을 사용하려면 프레젠테이션을 처리하고 애니메이션을 해제할 수 있는 전환 대리자를 제공해야 합니다.이 내용은 WWDC 2013 https://developer.apple.com/wwdc/videos/ ?id=218의 'View Controller를 사용한 맞춤형 전환' 토크에서 요약되어 있으며, 전환 딜러를 직접 구현하는 방법도 다룹니다.

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

iOS8+

iOS8+에서는 이제 새로운 모달 프레젠테이션 스타일 UIModal PresentationOverCurrentContext를 사용하여 투명한 배경으로 뷰 컨트롤러를 표시할 수 있습니다.

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

해결됨: 문제를 해결했습니다.그것은 아이폰과 아이패드 모두에 매우 잘 작동합니다.검은색 배경이 없는 모달 뷰 컨트롤러는 색상만 선명하고 투명합니다.UIModal Presentation FullScreen을 UIModal Presentation CurrentContext로 변경해야 합니다.정말 간단하군요!

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은 새로운 양식 프레젠테이션 스타일인 UIModal Presentation Custom을 도입하여 iOS가 표시된 뷰 컨트롤러 아래의 뷰를 제거하지 못하도록 했습니다.그러나 이 모달 프레젠테이션 스타일을 사용하려면 프레젠테이션을 처리하고 애니메이션을 해제할 수 있는 전환 대리자를 제공해야 합니다.이 내용은 WWDC 2013 https://developer.apple.com/wwdc/videos/ ?id=218의 'View Controller를 사용한 맞춤형 전환' 토크에서 요약되어 있으며, 전환 딜러를 직접 구현하는 방법도 다룹니다.

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

따라서 시각적 사고를 가진 사람들과 스토리보드 팬들은 다음과 같은 일을 할 수 있습니다.

뷰 컨트롤러 표시

컨텍스트 정의

표시된 보기 컨트롤러

프레젠테이션:

Swift 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 속성을 다음과 같이 설정하기만 하면 됩니다(nb).프레젠테이션은 "전체 화면에서"일 수도 있습니다.

여기에 이미지 설명 입력

iOS7과 iOS8에서 작동하는 가장 쉬운 방법은 iOS8 때문에 modallyPresentedVC(modallyPresentedVC)에서 presentationStyle을 UIModalPresentationOverCurrentContext에 추가하는 것입니다.

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

및 iOS7로 인해 VC(모달로 표시되는 컨트롤러)를 표시하는 UIModalPresentationCurrentContext:

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

왜냐하면 iOS7과 iOS8에서는 상황이 다르게 처리되기 때문입니다.물론 탐색 컨트롤러 속성을 사용하지 않는 경우에는 탐색 컨트롤러 속성을 설정할 필요가 없습니다.도움이 되길 바랍니다.

Swift2 버전:

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)

다른 방법(사용자 지정 전환을 생성할 필요가 없으며 iOS 7에서 작동)

스토리보드 사용:

자유 크기로 하위 보기 컨트롤러를 만들고 보기 너비를 500x500(예:)으로 설정한 후 다음 방법을 추가합니다.

- (void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];
    self.view.superview.bounds = CGRectMake(0, 0, 500, 500);
    self.view.superview.backgroundColor = [UIColor clearColor];
}

그런 다음 양식 시트를 사용하여 모달 세그먼트를 만들고 테스트합니다.

사용자 지정 segue가 포함된 iOS 7 솔루션:

CustomSegue.h
#import <UIKit/UIKit.h>

    @interface CustomSegue : UIStoryboardSegue <UIViewControllerTransitioningDelegate, UIViewControllerAnimatedTransitioning>

    @end



CustomSegue.m
#import "CustomSegue.h"

@implementation CustomSegue

-(void)perform {

    UIViewController* destViewController = (UIViewController*)[self destinationViewController];
    destViewController.view.backgroundColor = [UIColor clearColor];
    [destViewController setTransitioningDelegate:self];
    destViewController.modalPresentationStyle = UIModalPresentationCustom;
    [[self sourceViewController] presentViewController:[self destinationViewController] animated:YES completion:nil];
}


//===================================================================
// - UIViewControllerAnimatedTransitioning
//===================================================================

- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext {
    return 0.25f;
}

- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext {

    UIView *inView = [transitionContext containerView];
    UIViewController* toVC = (UIViewController*)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    UIViewController* fromVC = (UIViewController *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];

    [inView addSubview:toVC.view];

    CGRect screenRect = [[UIScreen mainScreen] bounds];
    [toVC.view setFrame:CGRectMake(0, screenRect.size.height, fromVC.view.frame.size.width, fromVC.view.frame.size.height)];

    [UIView animateWithDuration:0.25f
                     animations:^{

                         [toVC.view setFrame:CGRectMake(0, 0, fromVC.view.frame.size.width, fromVC.view.frame.size.height)];
                     }
                     completion:^(BOOL finished) {
                         [transitionContext completeTransition:YES];
                     }];
}


//===================================================================
// - UIViewControllerTransitioningDelegate
//===================================================================

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {

    return self;
}

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
    //I will fix it later.
    //    AnimatedTransitioning *controller = [[AnimatedTransitioning alloc]init];
    //    controller.isPresenting = NO;
    //    return controller;
    return nil;
}

- (id <UIViewControllerInteractiveTransitioning>)interactionControllerForPresentation:(id <UIViewControllerAnimatedTransitioning>)animator {
    return nil;
}

- (id <UIViewControllerInteractiveTransitioning>)interactionControllerForDismissal:(id <UIViewControllerAnimatedTransitioning>)animator {
    return nil;
}

@end

하이테크 코드 기반 솔루션.

나를 위한 이 작품:

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

    vc.view.backgroundColor = [UIColor clearColor];
    self.modalPresentationStyle = UIModalPresentationCurrentContext;
#ifdef __IPHONE_8_0
    if(IS_OS_8_OR_LATER)
    {
        self.providesPresentationContextTransitionStyle = YES;
        self.definesPresentationContext = YES;
        [vc setModalPresentationStyle:UIModalPresentationOverCurrentContext];
    }
#endif


    [self presentViewController:vc animated:NO completion:nil];

MMPushNotificationViewControllerTransparent View 컨트롤러이며 또한MMPushNotificationViewController의 보기 색을 선명한 색으로 표시합니다.이제 제가 수행한 모든 작업과 투명 뷰 컨트롤러를 만들었습니다.

iOS7의 경우

이제 iOS7 사용자 지정 전환을 사용하여 다음과 같은 방법으로 이를 달성할 수 있습니다.

MyController * controller = [MyController new];
[controller setTransitioningDelegate:self.transitionController];
controller.modalPresentationStyle = UIModalPresentationCustom;
[self controller animated:YES completion:nil];

사용자 지정 전환을 생성하려면 다음 두 가지가 필요합니다.

  • 전환 딜러 개체(구현)<UIViewControllerTransitionDelegate>)
  • "애니메이션 전환" 개체(구현)<UIViewControllerAnimatedTransitioning>)

사용자 지정 전환에 대한 자세한 내용은 튜토리얼에서 확인할 수 있습니다.

iOS7iOS8에서 잘 작동합니다.

UIViewController* vc=[[UIViewController alloc]initWithNibName:@"VC" bundle:nil];

vc.view.alpha=0.7;
[vc setModalPresentationStyle:UIModalPresentationOverCurrentContext];

self.navigationController.modalPresentationStyle = UIModalPresentationCurrentContext;

[self presentViewController:vc animated:NO completion:nil];

창을 보기에 '다시 추가'할 수도 있습니다.

OneViewController *vc = [[OneViewController alloc] init];
if ([self respondsToSelector:@selector(presentViewController:animated:completion:)]) {
    [self presentViewController:vc animated:YES completion:nil];
} else {
    [self presentModalViewController:vc animated:YES];
}

[[[UIApplication sharedApplication] keyWindow] insertSubview:self.view atIndex:0];

그리고 이런 방식으로, 발표는 애니메이션이 될 수 있습니다.

iOS 7의 경우, 인터페이스 빌더를 사용해야만 모달 프레젠테이션과 관련된 모든 뷰 컨트롤러에서 프레젠테이션을 "Over Current Context"로 설정할 수 있습니다.내비게이션 컨트롤러도 마찬가지입니다.

예를 들어 다음과 같은 모든 뷰 컨트롤러에 설정합니다.

NavController -> RootViewController -> ModalViewController

여기에 이미지 설명 입력

Storyboard/Interface Builder를 많이 사용하지는 않았지만, 보기에 선명한 색상(즉, 보기에 선명한 색상)을 지정하는 것이 눈에 띕니다.100% 알파/시스루) 및 불투명함(0% 알파-완전 고체)을 표시합니다.이 두 가지는 서로 맞지 않는 것 같습니다.나는 논평할 것입니다.self.view.opaque = YES;줄을 서서 그때 작동하는지 확인합니다 ;)

아, 제가 방금 생각한 또 다른 것은 -- 당신의 뷰 컨트롤러가 알파 배경을 가지고 있다는 것은 전적으로 가능하지만, 물론 알파는 프로그램의 기본 창이나 루트 뷰 컨트롤러의 색상까지 보여줄 것입니다. 기본적으로 검은색입니다.전체 앱의 기본 계층은 무엇에 대해 투명한 배경을 가질 수 없습니다.뒤에 뭐가 있죠?투명성을 통해 볼 수 있는 무언가가 있어야 합니다.이해 하셨나요?

표시 보기에서 "self.modalPresentationStyle = UIModalPresentationCurrentContext;"를 사용하면 됩니다.

잘 될 거예요 :)

언급URL : https://stackoverflow.com/questions/11236367/display-clearcolor-uiviewcontroller-over-uiviewcontroller

반응형