iphone - CGRectMake 不适用于 UIView

标签 iphone ios objective-c uiview

我今天花了几个小时只是为了在我的应用程序加载时隐藏 PickerView,但问题不在于 PickerView。它与 CGRectMake 一起使用。

我在 Xcode 上尝试了一个简单的项目,只是为了向您展示 CGRectMake 对我不起作用...

这是我的 Storyboard(灰色区域是 UIView 组件):

enter image description here

这是我的界面:

#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 不能处理我的情况?问题出在哪里?

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

enter image description here

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

enter image description here

最佳答案

如果您为 Storyboard 启用了 AutoLayout,则更改 View 的 frame 将不起作用。

您不能直接使用 AutoLayout 更改框架。你必须改变它们周围的约束。

如果您为 Storyboard 禁用 AutoLayout,它将起作用。

关于iphone - CGRectMake 不适用于 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18850871/

相关文章:

iphone - 在 ARC 下收到内存警告时,我应该将强 IBOutlet 设置为 nil 吗?

iOS9 Developer Trust App 无网络连接错误

iphone - 使用多线程时如何锁定方法?

Objective-C 前向声明与#imports

objective-c - 将 NSString 转换为 Integer 并检查它是否小于或等于某个值

iphone - 在屏幕上居中放置一组按钮

iphone - Apple 因恢复 IAP 而拒绝了我的 App

ios - 用于循环多次初始化的Objective C++失败

iphone - 处理大数字

ios - 将 TableView 点击位置转换为单元格 View 位置