CGRectMake does not work with UIView

I spent the hours of my day today to hide PickerView when my application is loaded, but the problem is not in PickerView. this is using CGRectMake.

I tried a simple Xcode project to show you that CGRectMake is not working for me ...

here is my storyboard (gray area is a UIView component):

enter image description here

and here is my interface:

#import <UIKit/UIKit.h> @interface ViewController : UIViewController @property (strong, nonatomic) IBOutlet UIView *container; @end 

and here is my implementation file:

 #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. _container.frame = CGRectMake(0, 0, 320, 204); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end 

this is very simple code, not infected with other codes ... but still, any numbers assigned to this CGRectMake do not cause the gray area to move. I changed the value of X, Y, but the gray UIView is the same as what you see on the storyboard.

Why is CGRectMake not working on my case? where is the problem?

UPDATE: I see that startup is checked in my inspector window

enter image description here

UPDATE: here is my connection inspector

enter image description here

0
source share
3 answers

If AutoLayout enabled for the Storyboard , then changing the frame view will not work.

You cannot directly change frames using AutoLayout . You must change the restrictions around them.

If you disable AutoLayout for the Storyboard , it will work.

+11
source

Make sure your IBOUTLET connection is connected to the view.

+1
source

CGrectmake only works because you set the frame size to CGRectMake (0, 0, 320, 204); according to size, the user view will be visible inside the main view if you want to hide the x or y coordinates with changing the value like this. Then do not forget to uncheck autolayout

 container.frame = CGRectMake(200, 0, 320, 204); 
+1
source

Source: https://habr.com/ru/post/893957/


All Articles