简体   繁体   English

使用GLKit在-glkView:drawInRect中检测-snapshot调用

[英]Detect -snapshot call in -glkView:drawInRect: using GLKit

I'm looking if -glkView:drawInRect: can detect that it's drawing for -snapshot method, rather than the normal way, where the view will be displayed to the user. 我在寻找-glkView:drawInRect:可以检测到它正在为-snapshot方法绘制,而不是正常的视图向用户显示的方式。 It's so I can detect how to draw the view correctly. 这样我就可以检测到如何正确绘制视图。 My attempt at detecting the difference in view was to compare the view passed to -glkView:drawInRect: with the GLKViewController's view: 我尝试检测视图的差异是将传递给-glkView:drawInRect:的视图与GLKViewController的视图进行比较:

// standard function GLKViewController
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
    if ((self.view != view)) NSLog(@"drawing for snapshot");
    // draw code ...
}

But no luck. 但是没有运气。 Another method I was considering was to create a boolean variable that would be set whenever -snapshot is called and -glkView:drawInRect: would reset it after it has drawn the snapshot specific view. 我正在考虑的另一种方法是创建时,将设置一个布尔变量-snapshot被调用, -glkView:drawInRect:它已经引起了快照特定视图后会重置。 But that seems dirty, and may cause multiple bugs, especially if drawing at 60 fps. 但这似乎很脏,并且可能会导致多个错误,尤其是在以60 fps的速度绘制时。

Do you give any recommendations or examples for detecting if -glkView:drawInRect: is drawing for the -snapshot method? 您是否提供任何建议或示例来检测-glkView:drawInRect:是否正在绘制-snapshot方法?

Thanks in advance 提前致谢

Subclass GLKView and overwrite the snapshot method to something like this: 子类GLKView并将snapshot方法覆盖为类似以下内容:

- (UIImage *)snapshot
{
    self.isDrawingSnapshot = YES;

    UIImage *result = [super snapshot];

    self.isDrawingSnapshot = NO;
    return result;
}

Instead of a property, you can also use a custom delegate to notify your view controller or post a NSNotification . 除了属性,您还可以使用自定义委托来通知您的视图控制器或发布NSNotification

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM