【发布时间】:2013-06-06 13:04:57
【问题描述】:
我正在尝试对提示用户添加通行证时显示的视图进行快照。
目标是能够从给定的 pkpass 生成图像
我希望这样的事情可以奏效:
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"columbus" ofType:@"pkpass"];
PKPass *pass = [[PKPass alloc] initWithData:[NSData dataWithContentsOfFile:filePath] error:nil];
PKAddPassesViewController *pkAddPassesViewController = [[PKAddPassesViewController alloc] initWithPass:pass];
[self presentViewController:pkAddPassesViewController animated:YES completion:^(){
UIImage *image = [pkAddPassesViewController.view captureView];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[self.view addSubview:imageView];
}];
使用 captureView 是:
- (UIImage *)captureView
{
CGRect screenRect = self.bounds;
UIGraphicsBeginImageContext(self.bounds.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor clearColor] set];
CGContextFillRect(ctx, screenRect);
[self.layer renderInContext:ctx];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
你猜怎么着?我错了:
我试过了:
使用完成回调和animationFinished回调
设置隐藏属性
使用计时器确保在截取屏幕截图时可以在屏幕上看到通行证
拍摄父视图的快照
我的想法已经用完了,所以任何建议都值得赞赏 提前致谢
哦,我在这里上传了一个最小的项目: https://github.com/framp/demo-capturing-passbook
编辑: 我可以拍摄其他视图的快照,并且可以使用上面的代码很好地加载其他 UIImage。 返回的 UIImage 是空白图片
【问题讨论】:
-
这是我下周要与 Apple 讨论的事项之一。 PKPassViewController 似乎有些异常。如果我找到了,或者他们可以告诉我一个解决方案,我会在这里发布。
-
我希望他们不是故意的(例如,阻止开发人员生成通行证图像)
-
我也想过这个问题。我可以想到一些可能会带来安全风险的情况,但归根结底,我认为没有理由证明故意阻止是合理的。
标签: iphone ios objective-c passbook