Unable to resize UIView frame

I have a custom uiview that I am trying to update the frame size. I do it this way in the method after clicking it. The method is called and the frame value changes, but nothing happens on the screen!

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");
    }
+3
source share
4 answers

I think you have connected self.view to UIView's Interface Builder.

To change the UIView frame, Interface Buildergo to File Inspectorand uncheck the box Use Autolayout, then change the frame in the code.

Hope this helps.

+14
source

You need to configure the frame in viewDidAppear (not viewDidLoad).

- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];

CGRect frame = self.tableView.frame;
frame.origin.y += 100.0;
frame.size.height -= 100.0;
self.tableView.frame = frame;
}

Apparently, this has something to do with table views in navigation controllers.

+11

, , Auto Layout . , .

- (void)viewDidAppear:(BOOL)animated {
    dispatch_async(dispatch_get_main_queue(), ^{
        box.frame = CGRectMake(20, 20, 100, 73)];
});
+4

[self.view reloadInputViews]commonly used for FirstResponders. I don’t have a big idea about your custom view, but I think that for just the settings, a frame that you can use:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

viewFrame.frame=frame;//Frame Defined by you 
[UIView commitAnimations]; 

may give a better solution if I look at your custom view.

-1
source

All Articles