如何在IOS中实现自定义形状的电影?
我有一个UIBezierPath和CAShapeLayer。我想以那种形式展示电影。
我正在寻找像歪斜的效果 - http://i57.tinypic.com/16020ps.jpg
我使用QR码阅读器,在那里我得到了找到的qr码的边界(UIBezierPath)。我希望能够通过qr代码显示视频以实现AR效果。
感谢您的帮助!
答案 0 :(得分:0)
您可以通过在MPMoviePlayerController视图顶部创建遮罩层来实现此目的。
我刚刚通过创建一个简单的单一视图项目来测试它。我添加了QuartzCore和MediaPlayer框架。
这是来自ViewController.m的代码:
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
#import <MediaPlayer/MediaPlayer.h>
@interface ViewController ()
@property (nonatomic, strong) MPMoviePlayerController *movieController;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"myMovie" ofType:@"mov"];
NSURL *url = nil;
if (moviePath != nil) {
url = [NSURL fileURLWithPath:moviePath];
}
self.movieController = [[MPMoviePlayerController alloc] initWithContentURL:url];
self.movieController.view.frame = CGRectMake(50, 50, 400, 400);
[self.view addSubview:self.movieController.view];
[self.movieController play];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = self.movieController.view.bounds;
UIBezierPath* bezierPath = [UIBezierPath bezierPath];
[bezierPath moveToPoint: CGPointMake(118.81, 189.76)];
[bezierPath addCurveToPoint: CGPointMake(188.77, 37.51) controlPoint1: CGPointMake(118.81, 189.76) controlPoint2: CGPointMake(138.99, 36.06)];
[bezierPath addCurveToPoint: CGPointMake(255.06, 158.26) controlPoint1: CGPointMake(238.56, 38.96) controlPoint2: CGPointMake(226.1, 78.56)];
[bezierPath addCurveToPoint: CGPointMake(369.21, 200.26) controlPoint1: CGPointMake(284.02, 237.96) controlPoint2: CGPointMake(314.4, 134.08)];
[bezierPath addCurveToPoint: CGPointMake(269.79, 300.02) controlPoint1: CGPointMake(424.02, 266.44) controlPoint2: CGPointMake(319.71, 329.77)];
[bezierPath addCurveToPoint: CGPointMake(151.95, 300.02) controlPoint1: CGPointMake(219.86, 270.26) controlPoint2: CGPointMake(202.68, 327.08)];
[bezierPath addCurveToPoint: CGPointMake(15.71, 284.27) controlPoint1: CGPointMake(101.22, 272.95) controlPoint2: CGPointMake(-0.1, 369.78)];
[bezierPath addCurveToPoint: CGPointMake(118.81, 189.76) controlPoint1: CGPointMake(31.51, 198.75) controlPoint2: CGPointMake(118.81, 189.76)];
[bezierPath closePath];
maskLayer.fillColor = [[UIColor whiteColor] CGColor];
maskLayer.backgroundColor = [[UIColor clearColor] CGColor];
maskLayer.path = [bezierPath CGPath];
self.movieController.view.layer.mask = maskLayer;
}
@end
(bezier路径是在PaintCode中快速创建的帽子形状,所以它有点奇怪。)