good guy
good guy

Reputation: 569

iPhone: how use NSTimer to hide UIButton and take screen shot

hi how to implement NSTimer to take screen shot after hidding the UIButton,can you tell me how to implement this with EXAMPLE. First UIButton has to hide and Screen shot has to take the screen have a nice day

Upvotes: 1

Views: 354

Answers (2)

kgutteridge
kgutteridge

Reputation: 8981

To take a screenshot of a particular section of the screen at a given time use something like this

CGRect screenRect = CGRectMake(0, 0, 200, 200);
UIGraphicsBeginImageContext(screenRect.size);

CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextFillRect(ctx, screenRect);
//you probably need an offset, adjust here
CGContextTranslateCTM(ctx, -20, -20);
[self.view.layer renderInContext:ctx];

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

//if you want to save this image to the photo album uncomment the next line
//UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil);
UIGraphicsEndImageContext();

Wrap all of this up in a method called takePhoto and you can just use NSTimer to trigger

[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(takePhoto:) userInfo:nil repeats:YES];

Upvotes: 1

Fabio Poloni
Fabio Poloni

Reputation: 8371

Here's how to take a Screenshot of your Window:

http://fmwebschool.com/blog/2008/10/01/taking-screenshots-with-the-iphone-sdk/

For the rest:

[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(count) userInfo:nil repeats:YES];

- (void)count {
counter++;
if (counter == secondsToWait) {
button.alpha = 0;
//Take Screenshot here
}
}

Upvotes: 3

Related Questions