James Anderson
James Anderson

Reputation: 566

Getting the outer CGRect

I have two UIViews, both of which obviously have CGRects each. One UIView fills the screen whereas the other just fills part of it in the middle. I have the CGRect of the smaller UIView, but how can I get the CGRect of the one outside of it - excluding the size of the smaller one so that the background can be dimmed, but not the content of the inner UIView?

This is what my UIViewController looks like so you can get a better idea of what I'm trying to do:

enter image description here

I want to dim the outer UIView, not the inner one - but I don't have the CGRect of the outer one excluding the inner UIView so I've had to do it the other way around for now.

Upvotes: 0

Views: 190

Answers (2)

EarlyRiser
EarlyRiser

Reputation: 736

So, it looks to me like the outer view is responsible for drawing your content and the inner view is your selection rectangle right?

If so, then I think you are going to want to draw your content twice when you have this selection mode active. You will:

  1. draw one pass dimmed - adjust the colors yourself (you can either draw the whole area or clip away the inner area using code from here)
  2. draw the second inner pass with a clip rect setup so only your content inside the rect for your selection rectangle is drawn

Or

  1. draw all your content like normal
  2. set your clipping mask (using code from here so that just the outer area is rendered) and then draw a black rect with some degree of transparency over your whole scene

Upvotes: 0

Alex Terente
Alex Terente

Reputation: 12036

A CGRect is a square size. If you want to know the outer aria you need to compute 4 CGRects. The top, left, right and bottom space.

Upvotes: 4

Related Questions