0

我今天花了几个小时在我的应用程序加载时隐藏 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 不适用于我的案子?问题出在哪里?

更新:我看到在我的检查器框中检查了自动布局

在此处输入图像描述

更新:这是我的连接检查员

在此处输入图像描述

4

3 回答 3

11

如果您已AutoLayout启用,Storyboard则更改frame视图将不起作用。

您不能直接使用AutoLayout. 你必须改变他们周围的约束。

如果您禁用它AutoLayoutStoryboard它将起作用。

于 2013-09-17T13:19:44.260 回答
1

CGrectmake 工作只是因为您将帧大小设置为 CGRectMake(0, 0, 320, 204); 根据大小,如果您想将 x 或 y 坐标更改为像这样的超出范围的值,自定义视图将在主视图中可见。然后不要忘记取消选中自动布局

container.frame = CGRectMake(200, 0, 320, 204);
于 2013-09-17T13:24:52.667 回答
1

确保您的IBOUTLET连接与视图连接。

于 2013-09-17T13:15:14.727 回答