Comparison of two CGR

I needed to check that the frame of my view is equal to the given CGRect. I tried to do it like this:

CGRect rect = CGRectMake(20, 20, 20, 20); if (self.view.frame == rect) { // do some stuff } 

However, I received the error message Invalid operands to binary expression('CGRect' (aka 'struct CGRect') and 'CGRect') . Why can't I just compare two CGRect s?

+83
comparison ios objective-c cocoa-touch cgrect
Oct 13 '12 at 22:12
source share
3 answers

Use this:

 if (CGRectEqualToRect(self.view.frame, rect)) { // do some stuff } 
+211
Sep 16 '13 at 3:44 on
source share

See the documentation for CGRectEqualToRect ().

 bool CGRectEqualToRect ( CGRect rect1, CGRect rect2 ); 
+39
Oct 13
source share

In Swift 3, it will be:

 frame1.equalTo(frame2) 
+4
Jun 19 '17 at 16:11
source share



All Articles