[英]iOS make video background blur
您只需要蒙版模糊視圖,請嘗試使用以下代碼:
@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;
}
效果就像這張照片:
您可以將遮罩層的路徑更改為所需的任何形狀,如果需要模糊視頻,只需將imageV更改為所需的視圖即可。
希望它能對您有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.