XCode8 origin parameters are ignored


#1

I’ve created an empty project after reading through the instructions to do so. I did include a launchscreen storyboard but no main.storyboard. AppDelegate.m looks like this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    CGRect firstFrame = CGRectMake(20, 30, 400, 600);
    BNRHypnosisView *firstView = [[BNRHypnosisView alloc] initWithFrame:firstFrame];
    firstView.backgroundColor = [UIColor redColor];
    [self.window addSubview:firstView];
    
    CGRect secondFrame = CGRectMake(20, 30, 120, 600);
    BNRHypnosisView *secondView = [[BNRHypnosisView alloc] initWithFrame:secondFrame];
    secondView.backgroundColor = [UIColor blueColor];
    [firstView addSubview:secondView];
    
    
    
    self.window.rootViewController = [[UIViewController alloc] init];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

When rendered on screen the origin parameters are completely ignored (20, 30) might as well be 0, 0. The secondView also is not nested inside the firstView (it’s not at all visible when made a child of firstView but does render if made a child of self.window).

I’m not sure what I’m missing.


#2


#3

What do you get if you replace the BNRHypnosisView with UIView?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    CGRect firstFrame = CGRectMake (20, 30, 200, 200);
    UIView *firstView = [[UIView alloc] initWithFrame:firstFrame];
    firstView.backgroundColor = [UIColor redColor];
    
    CGRect secondFrame = CGRectMake (20, 30, 100, 100);
    UIView *secondView = [[UIView alloc] initWithFrame:secondFrame];
    secondView.backgroundColor = [UIColor blueColor];
    [firstView addSubview:secondView];

    UIViewController *RVC = [[UIViewController alloc] init];
    RVC.view.frame = self.window.bounds;
    [RVC.view addSubview:firstView];

    self.window.rootViewController = RVC;
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    return YES;
}

PS: Add your firstView to your view controller’s view not to window.