CGRect x and y not working in BNRHypnosisView


If I create the BNRHypnosisView class (Cocoa Touch) as a UIView subclass with the requested CGRect “frame” property, all rectangles are drawn at the left-top of the screen instead of the x and y which are set using CGRectMake().

CGRect firstFrame = CGRectMake(160, 240, 100, 150);
BNRHypnosisView *firstView = [[BNRHypnosisView alloc] initWithFrame: firstFrame];
firstView.backgroundColor = [UIColor redColor];
[self.window addSubview: firstView];

However, if I do this using a direct UIView instance, things work as they should.

CGRect testFrame = CGRectMake(300, 300, 10, 10);
UIView *testView = [[UIView alloc] initWithFrame: testFrame];
testView.backgroundColor = [UIColor blackColor];
[self.window addSubview];

I am using XCode 5.1.1 on Mac OS 10.9.3.

What could be going wrong?



I found the problem… from page 89 (Views and frames) I understood that I had to enter this code in the BNRHypnosisView.h file:

Now I understand the text meant to say that this property is already present in the parent class (UIView), so I created a problem with this code. I found the solution after realizing that this line was the only difference between the parent class and my custom class. Commenting it out made the app work normal, and changing “frame” to e.g. “customFrame” too.

Apparently I misunderstood…


I did the same error in my coding…


I made the same mistake :angry: