2016-08-18 152 views
0

我正在製作視頻應用程序,我試圖添加視頻的模糊背景like that並根據幻燈片值控制模糊效果。我正在使用Objectivc-C進行編碼。任何人都可以幫助我,我應該怎麼做?iOS使視頻背景模糊

回答

0

你只需要遮蔽模糊觀點,嘗試使用此代碼:

@interface ViewController() 

@property UISlider *slider; 
@property UIVisualEffectView *visualEffectView; 

@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

    //VisableRect = 100,100,200,200 

    //Add a backgroun picture 
    UIImageView* imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 100)]; 
    imageV.image = [UIImage imageNamed:@"test"]; 
    [self.view addSubview:imageV]; 

    _visualEffectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; 
    _visualEffectView.frame = imageV.frame; 
    _visualEffectView.alpha = 1.0; 
    [self.view addSubview:_visualEffectView]; 

    //create path 
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRect:imageV.bounds]; 
    UIBezierPath *otherPath = [[UIBezierPath bezierPathWithRect:CGRectMake(100, 100, 200, 200)] bezierPathByReversingPath]; 
    [maskPath appendPath:otherPath]; 

    //set mask 
    CAShapeLayer *maskLayer = [CAShapeLayer layer]; 
    maskLayer.path = maskPath.CGPath; 
    [_visualEffectView.layer setMask:maskLayer]; 

    _slider = [[UISlider alloc] initWithFrame:CGRectMake(0, imageV.frame.size.height, 200, 20)]; 
    _slider.minimumValue = 0; 
    _slider.maximumValue = 1; 
    _slider.value = 1; 
    [_slider addTarget:self action:@selector(updateValue:) forControlEvents:UIControlEventValueChanged]; 
    [self.view addSubview:_slider]; 
} 

-(IBAction)updateValue:(id)sender{ 
    float sVaLue = _slider.value; 
    _visualEffectView.alpha = sVaLue; 
} 

,效果是這樣的畫面:

enter image description here

你可以改變遮罩層的路徑您想要的任何形狀,如果您需要模糊視頻,只需將imageV更改爲您想要的視圖。

希望它能幫助你。

+0

謝謝你的回答。 – Rupshikha

+0

它還存在一些問題?@Rupshikha –

+0

我還沒有嘗試過。當它播放時,我需要根據視頻幀的動態模糊效果。如果我遇到任何問題,我會讓你知道。 – Rupshikha