Cannot change UIView frame size

michaela picture michaela · Apr 30, 2012 · Viewed 12.9k times · Source

I have a custom uiview that i am trying to update the frame size. I do it like this in a method once it is clicked. The method is called, and the frame value changes, however on the screen nothing happens!

if (!touched) {

        GameBox *box = (GameBox *)[self.view viewWithTag:40];

        [box setFrame:CGRectMake(20, 20, 100, 73)];
        NSLog(@"%f", box.frame.origin.x);
        markButton.enabled = NO;
        guessButton.enabled = NO;
        [self.view reloadInputViews];

        NSLog(@"The action bar should now be hidden");
    }
    else if (touched) {
        guessButton.enabled = YES;
        markButton.enabled = YES;
        [self.view reloadInputViews];
        NSLog(@"The action bar should now be visible");
    }

Answer

Anh Nguyen picture Anh Nguyen · Feb 7, 2013

I guess you have hooked self.view to UIView in Interface Builder.

In order to change UIView frame, in Interface Builder go to File Inspector, and uncheck Use Autolayout, then in the code change the frame.

Hope this helps.