3

I am trying to implement this class so that I can capture a signature in my app:

PPSSignatureView *sign = [[PPSSignatureView alloc] initWithFrame:CGRectMake(10, 10, 500, 300)];
GLKViewController *glkView = [[GLKViewController alloc] init];
glkView.view = sign;
[self.view addSubview:glkView.view];

I've not worked with any openGL components before, so I'm not sure if I'm setting this up properly.

(PPSSignatureView is a subclass of GLKView)

RobDigital
  • 515
  • 1
  • 7
  • 19
Halpo
  • 2,982
  • 3
  • 25
  • 54
  • it's just not appearing in my view. I can only get it to work when i create a GLKView in storyboard and re-class it as PPSSignatureView. How can I do this programmatically? – Halpo May 19 '14 at 12:16
  • 1
    just used a xib in the end – Halpo May 19 '14 at 15:03

2 Answers2

5

Try to use 'initWithFrame:context' instead of initWithFrame:, see the code below:

EAGLContext *context = [EAGLContext alloc]initWithAPI:kEAGLRenderingAPIOpenGLES2];
PPSSignatureView *sign = [[PPSSignatureView alloc] initWithFrame:CGRectMake(10, 10, 500, 300) context:context];

It works for me, hope it helps!

Yang
  • 404
  • 7
  • 13
  • This worked for me, thank you. However I noticed that **EAGLContext** needs to be cleared before called for a second time. As a result I found it works more then once when I put `[EAGLContext setCurrentContext:nil]` before the context declaration. – Gram Jun 04 '15 at 20:29
  • 1
    Well, I notice that in the PPSSignatureView's dealloc method, it calls '[EAGLContext setCurrentContext:nil]' itself. I am assuming that you might have allocated more than one instance in memory? Is it a potentially memory leak? – Yang Jun 05 '15 at 10:41
  • 1
    Thanks, I took a look and if you pass in the context it seams to redecare it... Not sure why or if I understand it. – Gram Jun 05 '15 at 14:53
  • 1
    Yes, u r right, in the commonInit method, it been allocated again. Actually, if a nil passed as the context var, it works fine! Neither do I understand it... – Yang Jun 05 '15 at 15:04
0

How about adding it as a child view controller? Here is a sample:

[self addChildViewController:gLKVController];
[self.view addSubview:gLKVController.view];
[gLKVController didMoveToParentViewController:self];

I also used the same library and what I did is to embed the whole GLKViewController in a container view, then I resize and position the container view to what I wanted. Much easier for me, no code needed.

enter image description here

schystz
  • 800
  • 1
  • 8
  • 21