Question

I am trying to use GPUImageView in an iPhone app with Auto Layout. I tried something like:

_imageView = [[GPUImageView alloc] init];
[self addSubview:_imageView];
[_imageView setTranslatesAutoresizingMaskIntoConstraints:NO];    
_gpuImage = [[GPUImagePicture alloc] initWithImage:image];
[_gpuImage addTarget:_imageView];
[_gpuImage processImage];

The GPUImageView does not seem to be visible when I build and run the project.

If I remove all the Auto Layout constraints and initialize _imageView with initWithFrame, it is clearly visible. So, I am wondering if GPUImageView works with Auto Layout? Do I need to do something more to make it visible?

Update: GPUImage was installed via cocoa pods (~ 0.1.4). I am not sure if there were any new updates to the project that I missed.

Was it helpful?

Solution

The issue you're probably seeing is that UIImageView has an intrinsicContentSize, but GPUImageView does not. This means that without any width/height constraints, a UIImageView will display the image at its normal size, but not so with GPUImageView (depending on your other constraints, it could have a 0 width/height).

You can either add additional constraints on the GPUImageView to constrain its width and height to match what you expect, or you can subclass GPUImageView and implement intrinsicContentSize to return whatever you expect it to be. (It doesn't implement this normally because in general it can't determine a reasonable size would be; it renders to whatever size you make the view.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top