OK, i am making a Coloring app and it has a "Save" button that will take the screen shot of the view where the drawing is.
I have 6 images to color. In the intro page there 6 buttons, each will link you to a particular coloring page.
All are working well including the "Save" button except for one. All coloring views has the same contents and functions but in one image, it crashes the iPad whenever i clicked the "Save" button.
Here's some of my codes:
On Button Click:
[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];
Remove Flash:
- (void) removeFlash
{
[camFlash removeFromSuperview];
}
For the screenshot:
- (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);
}
This one is for the button that will show the coloring page:
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];