2009-09-30 4 views
7

다른 뷰 컨트롤러에 비해 모달 뷰 컨트롤러로 표시 할 수있는 재사용 가능한 UIViewController 하위 클래스를 만들고 싶습니다. 이 재사용 가능한 VC의 첫 번째 작업 중 하나는 UIActionSheet를 팝업하는 것입니다. 이렇게하기 위해, 액션 시트를 보여주기 위해 VC에서 기본 (빈) 뷰를 생성합니다.반투명 모달 UIViewController를 만들려면 어떻게해야합니까?

그러나 이것은 모달 VC가 튀어 나오면 부모 VC가 숨겨져 있기 때문에 좋지 않습니다. 따라서 액션 시트가 빈 배경 위에 떠있는 것처럼 보입니다. 작업 시트가 원본 (상위) vc 위에 표시 될 수 있다면 더 좋을 것입니다.

이 방법이 있습니까? 부모 vc의 뷰를 가져 와서 UIActionSheet에 애니메이션을 적용하는 것이 안전합니까?

+0

를 같은 문제가 : 당신이 할 수있는 것은 당신의 viewDidAppear 다음 파단의 자신의 뷰의 목록의 뒤쪽에있는 부모의 사진을 포함하는있는 UIImageView를 삽입합니다 parentController의보기의 사진을 찍을 :, 안에 있습니다. 모든 솔루션 ?? – Frade

답변

0

부모보기에서보기를 삽입하여 상위보기 컨트롤러 위에 표시 할 수 있습니다. 이 같은

뭔가 :

PseudoModalVC *vc = ...//initialization 
vc.view.backgroundColor = [UIColor clearColor]; // like in previous comment, although you can do this in Interface Builder 
vc.view.center = CGPointMake(160, -vc.view.bounds.size.height/2); 
[parentVC.view addSubView:vc.view]; 

// animation for pop up from screen bottom 
[UIView beginAnimation:nil context:nil]; 
vc.view.center = CGPointMake(160, vc.view.bounds.size.height/2); 
[UIView commitAnimation]; 
+1

이렇게하면 표시된보기 컨트롤러에서 "viewWillAppear"와 같은 메서드를 적절하게 호출해야합니다. UINavigationController와 모달 시스템은 당신을 위해 이것을 정상적으로 처리합니다. – DougW

-1

네. 발레리 (Valerii)가 말했듯이 현재보기 컨트롤러의보기 (또는 창의 하위보기)에 추가하고 화면에 애니메이션을 적용합니다.

이 할, 애니메이션과를 제거하려면 (내가 모달 뷰가 320 X 460 겠지하고이를 화면 떨어져 아래로 슬라이드됩니다) :

- (void)dismissModal 
{ 
    // animate off-screen 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; 
    [UIView setAnimationDuration:0.50]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; 

    self.view.frame = CGRectMake(0, 480, 320, 460); 

    [UIView commitAnimations]; 
} 

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context 
{ 
    // don't remove until animation is complete. otherwise, the view will simply disappear 
    [self.view removeFromSuperview]; 
} 
14

모달 뷰에서 애니메이션을 한 후, 그것을 크기가 부모보기와 크기가 같도록 크기가 조정됩니다.

#pragma mark - 
#pragma mark Sneaky Background Image 
- (void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 

    // grab an image of our parent view 
    UIView *parentView = self.parentViewController.view; 

    // For iOS 5 you need to use presentingViewController: 
    // UIView *parentView = self.presentingViewController.view; 

    UIGraphicsBeginImageContext(parentView.bounds.size); 
    [parentView.layer renderInContext:UIGraphicsGetCurrentContext()]; 
    UIImage *parentViewImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    // insert an image view with a picture of the parent view at the back of our view's subview stack... 
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds]; 
    imageView.image = parentViewImage; 
    [self.view insertSubview:imageView atIndex:0]; 
    [imageView release]; 
} 

- (void)viewWillDisappear:(BOOL)animated { 
    [super viewWillDisappear:animated]; 

    // remove our image view containing a picture of the parent view at the back of our view's subview stack... 
    [[self.view.subviews objectAtIndex:0] removeFromSuperview]; 
} 
+1

iOS 5의 경우 'parentViewController' 대신'presentingViewController'를 사용해야합니다. 나는 당신의 답을 그것을 포함하도록 업데이트했습니다. –

+0

이것은 대부분 잘 작동하지만, 시도 할 때 상위 뷰 이미지 상단에 20 px 갭이 생겨 상태 표시 줄에 (내가 추측하고있는) 원인이 있습니다. 그 문제를 해결하기위한 제안은 없습니까? – Mac

+0

업데이트 : 20 픽셀 위쪽으로 이미지 컨텍스트를 변환하여 픽스를 관리했지만 아무도 보이지 않는 이유가 궁금합니다. – Mac

관련 문제