ios 6中的图像拖动速度很慢

时间:2013-01-12 12:36:05

标签: ios objective-c xcode

我有一个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];
    }
}

感谢。

0 个答案:

没有答案