iphone - 在截图之前隐藏 UIButton

标签 iphone ios ios4

我需要截取应用程序的屏幕截图。有一个按钮可以触发它,但我不想让按钮出现在屏幕截图中。

我有以下代码:

- (IBAction) takePicture:(id) sender {
    button.hidden = YES;

    CGImageRef screen = UIGetScreenImage();
    UIImage* image = [UIImage imageWithCGImage:screen];
    CGImageRelease(screen);

    // Save the captured image to photo album
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
    button.hidden = NO;
}

但按钮仍然出现在屏幕截图中。我做错了什么?

最佳答案

我认为你在 runloop 可以刷新 View 之前捕获屏幕(即在它可以隐藏按钮之前)

你应该试着把你的代码改成这样:

- (IBAction) takePicture:(id) sender {
    button.hidden = YES;
    [self performSelector:@selector(takeScreenShot) withObject:nil afterDelay:0.1];                    
}

- (void)takeScreenShot {
    CGImageRef screen = UIGetScreenImage();
    UIImage* image = [UIImage imageWithCGImage:screen];
    CGImageRelease(screen);

    // Save the captured image to photo album
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
    button.hidden = NO;

}

这应该是运行循环移除按钮后的截图。

关于iphone - 在截图之前隐藏 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5144239/

相关文章:

iphone - 为什么 UIWebView 吃这么多内存?

ios - 用户界面 View 。为什么在其父范围之外的 subview 不接收触摸?

ios - 审核通过后,发布计划状态为“待开发人员发布”的应用程序吗?

iphone - NSNumber 与 Int

iphone - 计算核心数据中的不同项目

ios - cell.textlabel.text 无法正常工作

iphone - 增强现实标记iphone sdk

iphone - 从 Iphone App 在 Dropbox 中创建文件夹

objective-c - 将滤镜效果应用到 UIImage

iphone - 当多个本地通知触发时,如何增加应用程序图标徽章?