CGRectMake 不适用于 UIView [英] CGRectMake is not working with UIView
问题描述
我今天花了几个小时来在我的应用程序加载时隐藏 PickerView,但问题不在于 PickerView.它与 CGRectMake 一起使用.
I spent hours of my day today just to hide PickerView when my app is loaded, but the problem is not with the PickerView. it's with CGRectMake.
我在 Xcode 上尝试了一个简单的项目,只是为了向您展示 CGRectMake 对我不起作用...
I tried a simple project on Xcode just to show you that CGRectMake doesn't work for me...
这是我的故事板(灰色区域是 UIView 组件):
here's my storyboard (grey area is UIView component) :
这是我的界面:
#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 仍然像您在故事板上看到的一样.
it's very basic code, not contaminated with other codes... but still, any numbers given to that CGRectMake doesn't make that grey area move. I've changed X, Y value, but the grey UIView stand still just like what you see on storyboard.
为什么 CGRectMake 对我的案例不起作用?问题出在哪里?
why CGRectMake is not working on my case? where's the problem?
更新:我看到在我的检查器框中选中了自动布局
UPDATE : I see autolayout is checked on my inspector box
更新:这是我的连接检查器
UPDATE : here's my Connection inspector
推荐答案
如果您为 Storyboard
启用了 AutoLayout
然后更改 frame
一个视图不起作用.
If you have AutoLayout
enabled for the Storyboard
then changing the frame
of a view won't work.
您不能直接使用 AutoLayout
更改框架.你必须改变它们周围的约束.
You can't change frames directly using AutoLayout
. You have to change the constraints around them.
如果您为 Storyboard
禁用 AutoLayout
,它将起作用.
If you disable AutoLayout
for the Storyboard
it will work.
这篇关于CGRectMake 不适用于 UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!