Objective c 目标C:点击屏幕截图按钮时iPad崩溃

Objective c 目标C:点击屏幕截图按钮时iPad崩溃,objective-c,ios,ipad,screenshot,Objective C,Ios,Ipad,Screenshot,好的,我正在制作一个着色应用程序,它有一个“保存”按钮,可以截取图形所在视图的屏幕截图 我有6个图像的颜色。在介绍页面中有6个按钮,每个按钮都会将您链接到特定的着色页面 除了一个按钮外,包括“保存”按钮都工作正常。所有的彩色视图都有相同的内容和功能,但在一张图像中,每当我点击“保存”按钮时,它就会使iPad崩溃 以下是我的一些代码: 点击按钮: [self saveScreenshotToPhotosAlbum]; camFlash = [[UIImageView alloc]

好的,我正在制作一个着色应用程序,它有一个“保存”按钮,可以截取图形所在视图的屏幕截图

我有6个图像的颜色。在介绍页面中有6个按钮,每个按钮都会将您链接到特定的着色页面

除了一个按钮外,包括“保存”按钮都工作正常。所有的彩色视图都有相同的内容和功能,但在一张图像中,每当我点击“保存”按钮时,它就会使iPad崩溃

以下是我的一些代码:

点击按钮:

    [self saveScreenshotToPhotosAlbum];

    camFlash = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
    [camFlash setBackgroundColor:[UIColor whiteColor]];
    [camFlash setAlpha:0.0];
    [cbHolder addSubview:camFlash];
    [cbHolder bringSubviewToFront:camFlash];

    [UIView beginAnimations:@"Flash-On" context:NULL];
    [UIView setAnimationDuration:0.2];
    [UIView setAnimationRepeatAutoreverses:NO];
    [camFlash setAlpha:1.0];
    [UIView commitAnimations];

    NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"flash" ofType:@"wav"];
    AVAudioPlayer *flashSFX = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:soundPath] error:NULL];
    flashSFX.volume = 0.5;
    flashSFX.numberOfLoops = 0;
    self->camFlashSFX = flashSFX;
    if ([flashSFX currentTime] != 0) [flashSFX setCurrentTime:0];
    [flashSFX play];

    [self performSelector:@selector(removeFlash) withObject:nil afterDelay:0.2];
移除闪光灯:

- (void) removeFlash
{
    [camFlash removeFromSuperview];
}
对于屏幕截图:

- (UIImage*)captureView { 
    UIGraphicsBeginImageContext(CGSizeMake(1024, 768));    
    CGContextRef context = UIGraphicsGetCurrentContext();  
    [cbHolder.layer renderInContext:context];  
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();  
    UIGraphicsEndImageContext();  
    return img;
}

- (void)saveScreenshotToPhotosAlbum {
    UIImageWriteToSavedPhotosAlbum([self captureView], nil, nil, nil);
}
此按钮用于显示着色页面的按钮:

uc4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tpUncolored1.png"]];
    [uc4 setUserInteractionEnabled:YES];
    [uc4 setFrame:CGRectMake(0, 0, 1024, 768)];
    [cbHolder addSubview:uc4];

    clrd4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tpColored1.png"]];
    [clrd4 setUserInteractionEnabled:YES];
    [clrd4 setFrame:CGRectMake(0, 0, 1024, 768)];
    [cbHolder addSubview:clrd4];

    [UIView beginAnimations:@"fabe-out" context:NULL];
    [UIView setAnimationDuration:1.5];
    [clrd4 setAlpha:0.0];
    [UIView commitAnimations];

    [self performSelector:@selector(cb4) withObject:nil afterDelay:1.5];
我有一个错误:


线程5:EXC\u BAD\u访问(代码=1,地址=0xd9bbd40)

确保[self captureView]未被禁用nil@OmarAbdelhafith不,不是零。如果有异常,你能发布抛出的异常吗?再来一个。。。它在模拟器上正常运行。@OmarAbdelhafith Ok在这里。它说:线程5:EXC_BAD_ACCESS(代码=1,地址=0xd9bbd40)确保[self captureView]未被激活nil@OmarAbdelhafith不,不是零。如果有异常,你能发布抛出的异常吗?再来一个。。。它在模拟器上正常运行。@OmarAbdelhafith Ok在这里。它说:线程5:EXC\u BAD\u访问(代码=1,地址=0xd9bbd40)