【发布时间】:2013-09-21 22:50:50
【问题描述】:
我今天花了几个小时在我的应用程序加载时隐藏 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 不适用于我的案例?问题出在哪里?
更新:我看到在我的检查框上选中了自动布局
更新:这是我的连接检查器
【问题讨论】:
-
您是否在情节提要中启用了自动布局?
-
是的,请检查我的更新。你是这个意思吗?
-
CGRectMake 正在工作。我确定它正确设置了框架。但是,对于 UIView 不做出反应,这可能意味着稍后会进行一些布局(可能是自动布局?)。尝试覆盖 layoutSubviews 并且在里面什么都不做。
-
是的,AutoLayout 的规则 1。您不能更改任何视图的框架。您有将视图保持在适当位置的约束。您可以尝试更改框架,但它不起作用,因为约束将其固定到位。您可以关闭 AutoLayout 或更新约束,而不是使用
_container.frame = ...
标签: iphone ios objective-c uiview