2015-06-10 149 views
0

現在我使用LBBlurredImage模糊的圖像,但我想更改爲iOS8UIVisualEffectView模糊,而不是模糊效果時滾動

我很難實施,有什麼想法嗎?

實現與LBBLurredImage

- (void)updateData { 
    // Set up Screen 
    self.screenHeight = [UIScreen mainScreen].bounds.size.height; 
    //UIImage *background = [UIImage imageNamed:@"gray"]; 
    UIImage *background = [UIImage imageNamed:backgroundImageGlobal]; 

    // Background Image 
    self.backgroundImageView = [[UIImageView alloc] initWithImage:background]; 
    self.backgroundImageView.contentMode = UIViewContentModeScaleAspectFill; 
    [self.view addSubview:self.backgroundImageView]; 

    // Background Image Blurred 
    self.blurredImageView = [[UIImageView alloc] init]; 
    self.blurredImageView.contentMode = UIViewContentModeScaleAspectFill; 
    self.blurredImageView.alpha = 0.0; // 0.0 
    [self.blurredImageView setImageToBlur:background blurRadius:10 completionBlock:nil]; // blurRadius:10 
    [self.view addSubview:self.blurredImageView]; 
} 

- (void)scrollViewDidScroll:(UIScrollView *)scrollView { 
    CGFloat height = scrollView.bounds.size.height; 
    CGFloat position = MAX(scrollView.contentOffset.y, 0.0); 
    CGFloat percent = MIN(position/height, 1.0); 
    self.blurredImageView.alpha = percent; 
} 

我最好的拍攝到目前爲止我加/改變以前的代碼,用UIVisualEffectView實現:

// iOS8 
@property (nonatomic) UIVisualEffect *blurEffect; 
@property (nonatomic) UIVisualEffectView *visualEffectView; 

// iOS8 Blur 
self.blurredImageView = [[UIImageView alloc] init]; 
self.blurredImageView.contentMode = UIViewContentModeScaleAspectFill; 
self.blurredImageView.alpha = 0.0; 
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; 
UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; 
visualEffectView.frame = self.blurredImageView.bounds; 
[self.blurredImageView addSubview:visualEffectView]; 
[self.view addSubview:self.blurredImageView]; 

回答

0

我想通了。我用過:

// iOS8 Blur 
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; 
self.visualEffectViewGlobal = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; 
self.visualEffectViewGlobal.frame = self.view.bounds; 
self.visualEffectViewGlobal.alpha = 0.0; 
[self.view addSubview:self.visualEffectViewGlobal];