Bogdan Pop
Bogdan Pop

Reputation: 438

Instance of UIView subclass is not full screen even if its frame is the window bounds property

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

    CGRect frame = self.window.bounds;
    BNRHypnosisView *firstView = [[BNRHypnosisView alloc] initWithFrame:frame];
    [self.window addSubview:firstView];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

The instance of BNRHypnsosisView (subclass of UIView), firstView, has its frame equal to window bounds. Why it isn't full screen?

EDIT: In BNRHypnosis View , I had a @property (nonatomic) CGRect frame. That's the only thing I had in this subclass. After I deleted it ( i've seen i wasn't using it anywhere ) , everything worked fine. Can somebody tell me why?

Upvotes: 0

Views: 349

Answers (1)

Nicolas Buquet
Nicolas Buquet

Reputation: 3955

The declared "frame" property override the existing property "frame" of UIView. It is a fundamental property of any UIView in iOS. If you override it, you have to call [super setFrame:<frameValue>] in your implementation to not loose the base and mandatory functionnality.

This declared property is not present in the actual implementation of BNRHypnosisView on GitHub: https://github.com/rahims/iOS-Programming-The-Big-Nerd-Ranch-Guide/blob/master/Chapter-5/Hypnosister/Hypnosister/BNRHypnosisView.h

Upvotes: 1

Related Questions