我有一个 ipad 应用程序,具有适用于 ios 5 和 ios 6 的视频录制和图像拖动功能。
我使用“ScreenCapture”类文件进行视频录制,使用“Draggable”类文件进行图像拖动。
现在的问题是,当我使用“ScreenCapture”类时,图像拖动功能变得缓慢而且有点生涩。当我删除那个'ScreenCapture'类时,拖动工作正常(没有视频录制)。
这两个功能对于 ios 5 来说都很好。但是当尝试在 ios 6 中运行时,由于“ScreenCapture”,图像拖动变得很慢。
我怎样才能做到这一点?
**使用的代码:-
// For image dragging.......
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if (isImageRemove)
{
imgcharacter = [[UIImageView alloc]init];
imgobject = [[UIImageView alloc]init];
}
CGPoint pt = [[touches anyObject] locationInView:imgcharacter];
startlocation =pt;
imgcharacter.userInteractionEnabled=YES;
imgobject.userInteractionEnabled=YES;
int count;
if (isImageRemove)
{
Images = [[NSMutableArray alloc]init];
int value = [touch view].tag;
int inx=0;
for (int i1=0; i1<[[self.view subviews] count]; i1++) {
if ([[[[self.view subviews]objectAtIndex:i1]valueForKey:@"tag"]intValue]==value) {
inx=i1;
break;
}
}
NSLog(@"index = %d",inx);
count = [self.view.subviews count];
NSLog(@"count = %d",count);
UIView* subview;
if ((subview = [[self.view subviews] objectAtIndex:inx]))
{
if ([touch view].tag >0)
{
NSLog(@"subview = %@",subview);
[subview removeFromSuperview];
}
else {
NSLog(@"subview = %@",[self.view subviews]);
}
}
}
else
{
CGPoint location = [touch locationInView:self.view];
}
}
// For Video recording.......
- (IBAction)btnRecording_Pressed:(id)sender {
if (Isrecording ==YES)
{
[voiceRecorder stop];
[captureview stopRecording];
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *err = nil;
[audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];
if(err)
{
NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
return;
}
[audioSession setActive:YES error:&err];
err = nil;
if(err){
NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
return;
}
recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
[recordSetting setValue :[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
NSString *recorderFilePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
recorderFilePath = [recorderFilePath stringByAppendingPathComponent:@"tempRecording.caf"];
NSURL *urls = [NSURL fileURLWithPath:recorderFilePath];
err = nil;
voiceRecorder = [[ AVAudioRecorder alloc] initWithURL:urls settings:recordSetting error:&err];
if(!voiceRecorder){
NSLog(@"recorder: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
UIAlertView *alert =
[[UIAlertView alloc] initWithTitle: @"Warning"
message: [err localizedDescription]
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
return;
}
//prepare to record
[voiceRecorder setDelegate:self];
[voiceRecorder prepareToRecord];
//scrren short of screen
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(self.view.bounds.size);
[captureview.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * imageData = UIImageJPEGRepresentation(viewImage, 1.0);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
documentsDirectory = [documentsDirectory stringByAppendingPathComponent:@"VideoScreen.jpg"];
[imageData writeToFile:documentsDirectory atomically:YES];
[voiceRecorder record];
[captureview performSelector:@selector(startRecording) withObject:nil afterDelay:0];
Isrecording =NO;
[btnRecord setTitle:@"Stop" forState:UIControlStateNormal];
}
else if (!Isrecording)
{
imgDustbin.hidden =NO;
[[NSUserDefaults standardUserDefaults ] setValue:@"YES" forKey:@"DUSTBIN"];
[voiceRecorder stop];
[captureview stopRecording];
[self createVideo];
Isrecording=YES;
[btnRecord setTitle:@"Record" forState:UIControlStateNormal];
}
}
谢谢。