在更新之前截取UIView的屏幕截图

时间:2016-12-07 06:09:07

标签: ios objective-c screenshot uiblureffect

我有一个带有按钮的UIView,在点击时会显示一个填充屏幕一半的dropDownList。 我正在拍摄相同视图的屏幕截图(在点击按钮之前)并将其用作模糊背景。 我的问题是点击按钮后拍摄的截图,但我希望在点击按钮之前拍摄(初始屏幕)。

我尝试过以下代码

    -(void)ViewDidLoad
          {
              [self imageWithView:self.view];
              [self blurScreenshot];
           }

   - (UIImage *) imageWithView:(UIView *)view
       {
      UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque,[[UIScreen mainScreen] scale]);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
 return img;
}


 -(void)blurScreenshot
{
UIImage *pngImg = [self imageWithView:self.view];
   screenshot = [[UIImageView alloc]initWithFrame:CGRectMake(0,200,self.view.frame.size.width,self.view.frame.size.height-200)];

UIColor *tintColor =[UIColor colorWithWhite:1.0 alpha:0.2];
UIImage * bluredImage = [pngImg applyBlurWithRadius:2 tintColor:tintColor saturationDeltaFactor:1.5 maskImage:nil ];

screenshot.image = bluredImage;

}

- (IBAction)OnClickingIndicator:(id)sender {
    ++x;
   NSLog(@"log value%d",x);
   [self.childViewControllers[0] view].hidden = ! [self.childViewControllers[0] view].hidden;
if(x % 2 == 0)
{
    [self.view addSubview:screenshot];
    [self.view bringSubviewToFront:screenshot];

   }else
    {
    [screenshot removeFromSuperview];

    [ blurEffectView removeFromSuperview];
  }  
}

我的屏幕类似于此唯一的变化是在点击TimeLine之前必须拍摄截图并进行模糊处理,以便在点击TimeLine时将其用作背景。

enter image description here

0 个答案:

没有答案