好的,我正在制作一个着色应用程序,它有一个“保存”按钮,可以截取绘图所在视图的屏幕截图。
我有 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_BAD_ACCESS(代码=1,地址=0xd9bbd40)