在视频上旋转文字

时间:2016-06-01 07:37:50

标签: ios objective-c uigesturerecognizer

我已经创建了一个应用程序,其中我通过UITextView添加了一个文本,现在我想在这个文本中添加一些手势效果。我已经完成了但是它没有正常工作。 请尽快帮助我。

在文字中添加手势效果的代码 -

CALayer *aLayer = [CALayer layer];
aLayer.frame = CGRectMake(0, 0, 30, 30); //Needed for proper display.  We are using the app icon (57x57). If you use 0,0 you will not see it
aLayer.opacity = 0.75; //Feel free to alter the alpha here
//Create layer with watermark text instead of image
CGSize videoSize = [self.videoAsset naturalSize];
UITextView *textView =[[UITextView alloc]init];
textView.text = @"text here";
[textView setFont:[UIFont boldSystemFontOfSize:30]];
[textView setBackgroundColor: [UIColor clearColor]];
[textView setTextColor: [UIColor blackColor]];
textView.frame=CGRectMake(10,10,videoSize.width,videoSize.height);
[textView setReturnKeyType:UIReturnKeyDone];
[self.view addSubview:textView];
for (UIView * view in self.view.subviews) {

UIPanGestureRecognizer * recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panDetector:)];
recognizer.delegate = self;
[view addGestureRecognizer:recognizer];

// TODO: Add a custom gesture recognizer too

UIRotationGestureRecognizer * recognizer1 = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationDetector:)];
recognizer.delegate = self;
[view addGestureRecognizer:recognizer1];

}
CALayer *parentLayer = [CALayer layer];
CALayer *videoLayer = [CALayer layer];

parentLayer.frame = CGRectMake(0, 0, videoSize.width,  videoSize.height);
videoLayer.frame = CGRectMake(0, 0, videoSize.width, videoSize.height);
[parentLayer addSublayer:videoLayer];
[parentLayer addSublayer:aLayer];
[parentLayer addSublayer:textView.layer]; //ONLY IF WE ADDED TEXT
//Create composition
AVMutableVideoComposition* videoComp = [AVMutableVideoComposition  videoComposition];
videoComp.renderSize = videoSize;
videoComp.frameDuration = CMTimeMake(1, 30);
videoComp.animationTool = [AVVideoCompositionCoreAnimationTool          videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];
//Create instruction to insert layer
AVMutableVideoCompositionInstruction *instruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
instruction.timeRange = CMTimeRangeMake(kCMTimeZero, [mixComposition duration]);
AVAssetTrack *videoTrack = [[mixComposition tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
AVMutableVideoCompositionLayerInstruction* layerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:videoTrack];
instruction.layerInstructions = [NSArray arrayWithObject:layerInstruction];
videoComp.instructions = [NSArray arrayWithObject: instruction];

NSString *destPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0]stringByAppendingPathComponent:@"NewwatermarkVideo.mp4"];
NSURL *exportUrl = [NSURL fileURLWithPath:destPath];



if ([[NSFileManager defaultManager] fileExistsAtPath:destPath])
{
[[NSFileManager defaultManager] removeItemAtPath:destPath error:nil];
}



AVAssetExportSession *exporter = [[AVAssetExportSession alloc]     initWithAsset:mixComposition
                                                              presetName:AVAssetExportPresetHighestQuality];
exporter.outputURL=exportUrl;
exporter.outputFileType = AVFileTypeQuickTimeMovie;
exporter.shouldOptimizeForNetworkUse = YES;
exporter.videoComposition = videoComp;
[exporter exportAsynchronouslyWithCompletionHandler:^{
dispatch_async(dispatch_get_main_queue(), ^{
    [self exportDidFinish:exporter];
});
}];

0 个答案:

没有答案