2014-04-06 2 views
0

계산 결과를 표시하려는 모달 뷰가 있습니다. 모든 iOS7보기를 만들기 위해 blured 배경을 가진 팝업보기로 채색 된 배경을 원합니다.UIImage + ImageEffects가 장치에서 작동하지 않습니다.

사과에서 "UIImage + ImageEffects .h/m"파일을 사용하여 작업 할 수있었습니다.

이 모달 뷰의 viewDidLoad에 있습니다 :

- (void)viewDidLoad { 

    [super viewDidLoad]; 

    /* How it works 

    self.image is a screenshot of the VC presenting the modal view 

    1- we set the background as the screenshot of the previous viewControler 
    2- we hide the popup view 
    3- we set the background of the popup as a blured snapshot of its container view (self.view) 
    4- we unhide the popup view and set its radius 
    5- we create a tinted version of the background image (what we got from the previous view controller 
    6- we set the background of self.view to the tinted version 


    */ 

    // *** 1 *** 

    self.view.backgroundColor=[UIColor colorWithPatternImage:self.image]; 


    // *** 2 *** 

    self.containerView.hidden=YES; 


    // *** 3 *** 

    UIImage *pepe=[self bluredImageFromView:self.containerView withBackground:self.view withBackgroundTintColor:[UIColor colorWithWhite:1 alpha:0.75]]; 
    self.containerView.backgroundColor=[UIColor colorWithPatternImage:pepe]; 

    // *** 4 *** 

    self.containerView.hidden=NO; 
    self.containerView.layer.cornerRadius=4.5f; 

    // *** 5 *** 

    UIImage *tintedBackground =[self.image applyBlurWithRadius:0 
                 tintColor:[UIColor colorWithRed:0.85 green:0.85 blue:0.85 alpha:0.35] 
              saturationDeltaFactor:1.8 
                 maskImage:nil]; 
    // *** 6 *** 

    self.view.backgroundColor=[UIColor colorWithPatternImage:tintedBackground]; 


} 

는 시뮬레이터에 아주 잘 작동하지만 아이폰 (4S) onmy 시도 할 때 모달 뷰를 제시 할 때, 나는 검은있어 화면. 오류 없음, 콘솔에서 불평하지 않음, 아무런 의미가 없습니다.

의견이 있으십니까? 그것은 시뮬레이터 self.image에 그 보인다

하는 반면, 장치 거기에 nil이 아닌 viewDidLoad에

의 맨 처음에

if (!self.image) NSLog (@"self.image is empty"); 

:

편집

나는 코드를 추가 입니다. 부모 VC에서을 prepareForSegue에서 self.image를 인스턴스화하려고했지만 작동하지 않습니다.

답변

2

나는 당신의 bluredImageFromView가 작동하는 방법을 알고 있지만, 보안 (샌드 박스)는 (작동 이유를 설명 할 수 시뮬레이터와 (특히 resizableSnapshotViewFromRect:drawViewHierarchyInRect:와) 실제 iOS 장비 사이의 차이가 있지만, 다음하지 않습니다하지 않는)
rayworkerchich.com에서 thread을 확인하십시오. 누군가가 Apple 개발자 기술 지원에서 조언을 구할 수 있습니다. 이 예제 코드는 Apple에서 나온 것입니다.

- (IBAction)doBlurAndCrop:(id)sender { 

UIImage *snapshotImage; 

    /* draw the image of all the views below our view */ 
UIGraphicsBeginImageContextWithOptions(self.sourceImageView.bounds.size, NO, 0); 
BOOL successfulDrawHierarchy = [self.sourceImageView drawViewHierarchyInRect:self.sourceImageView.bounds afterScreenUpdates:YES]; 
if (successfulDrawHierarchy) { 
    snapshotImage = UIGraphicsGetImageFromCurrentImageContext(); 
} else { 
    NSLog(@"drawViewHierarchyInRect:afterScreenUpdates: failed - there's nothing to draw..."); 
} 
UIGraphicsEndImageContext(); 

if (successfulDrawHierarchy) { 

     /* calculate the coordinates of the rectangle we're interested in within the returned image */ 
    CGRect cropRect = CGRectOffset(self.targetImageView.frame, - self.sourceImageView.frame.origin.x, - self.sourceImageView.frame.origin.y); 

     /* draw the cropped section with a clipping region */ 
    UIGraphicsBeginImageContextWithOptions(cropRect.size, YES, 0); 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextClipToRect(context, CGRectMake(0, 0, cropRect.size.width, cropRect.size.height)); 
    CGRect targetRectangeForCrop = CGRectMake(-cropRect.origin.x, -cropRect.origin.y, snapshotImage.size.width, snapshotImage.size.height); 
    [snapshotImage drawInRect:targetRectangeForCrop]; 
    UIImage *croppedSnapshotImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

     /* apply a special effect to the resulting image and copy it into place on screen */ 
    UIColor *tintColor = [UIColor colorWithWhite:1.0 alpha:0.3]; 
    self.targetImageView.image = [croppedSnapshotImage applyBlurWithRadius:5 tintColor:tintColor saturationDeltaFactor:1.8 maskImage:nil]; 
} 
} 
+0

고맙습니다. 나는 실제로 레이 웬델 리히트의 튜토리얼에서 스 니프 코드 (snip code)를 받아 냈습니다. 여러분이 지적한이 스레드에 관한 것입니다. 당신이 제공하는이 코드로 제 방법을 수정했는데 이제는 매력처럼 작동합니다. 나는 너에게 충분히 감사 할 수 없다! – Marcal

+0

반갑습니다. 'applyBlurWithRadius : tintColor : saturationDeltaFactor : maskImage :'가 iPhone 4에서 작동하는지 궁금 할 것입니다. –

+0

제 4로만 완벽하게 작동한다고 말할 수 있습니다. 앱을 제출하기 전에 며칠 내 iPad 3에서 시험해 보겠습니다. – Marcal