我今天花了几个小时只是为了在我的应用程序加载时隐藏 PickerView,但问题不在于 PickerView。它与 CGRectMake 一起使用。
我在 Xcode 上尝试了一个简单的项目,只是为了向您展示 CGRectMake 对我不起作用...
这是我的 Storyboard(灰色区域是 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 静止不动,就像您在 Storyboard上看到的那样。
为什么 CGRectMake 不能处理我的情况?问题出在哪里?
更新:我看到在我的检查器框上选中了自动布局
更新:这是我的连接检查器
最佳答案
如果您为 Storyboard
启用了 AutoLayout
,则更改 View 的 frame
将不起作用。
您不能直接使用 AutoLayout
更改框架。你必须改变它们周围的约束。
如果您为 Storyboard
禁用 AutoLayout
,它将起作用。
关于iphone - CGRectMake 不适用于 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18850871/