CGRectMake不能使用UIView
我今天花了几个小时来隐藏PickerView,当我的应用程序被加载,但问题不在于PickerView。 它与CGRectMake。
我尝试了一个简单的项目在Xcode只是为了告诉你,CGRectMake不适合我…
这里是我的故事板(灰色区域是UIView组件):
这是我的界面:
#import <UIKit/UIKit.h> @interface ViewController : UIViewController @property (strong, nonatomic) IBOutlet UIView *container; @end
这里是我的实现文件:
#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
这是非常基本的代码,没有被其他代码污染…但是,任何给CGRectMake的数字都不会使灰色区域移动。 我已经改变了X,Y值,但是灰色的UIView仍然像你在故事板上看到的一样。
为什么CGRectMake不适合我的情况? 问题在哪里?
更新:我看到自动布局检查我的检查箱
更新:这是我的连接检查器
如果启用了Storyboard
AutoLayout
,则更改视图的frame
将不起作用。
您不能直接使用AutoLayout
更改框架。 你必须改变他们周围的约束。
如果你禁用AutoLayout
的Storyboard
它将工作。
确保您的
IBOUTLET
连接与视图连接。
CGrectmake只能工作,因为您将框架大小设置为CGRectMake(0,0,320,204); 根据大小自定义视图将在主视图内可见,如果你想隐藏更改x或y坐标到这样的界限值。 然后不要忘记取消select自动布局
container.frame = CGRectMake(200, 0, 320, 204);