Ios Obj C:UIView位于右下角

Ios Obj C:UIView位于右下角,ios,objective-c,uiview,Ios,Objective C,Uiview,我似乎不知道我做错了什么。我想在屏幕的右下角粘贴一个UIView,但对齐已关闭。在我看来我有$ int size = 50; CGRect frame = CGRectMake(self.view.frame.size.width - (size + 10), self.view.frame.size.height - (size + 10), size, size); UIView *colorView = [[UIView alloc]initWithFrame:frame]; colorV

我似乎不知道我做错了什么。我想在屏幕的右下角粘贴一个UIView,但对齐已关闭。在我看来我有$

int size = 50;
CGRect frame = CGRectMake(self.view.frame.size.width - (size + 10), self.view.frame.size.height - (size + 10), size, size);
UIView *colorView = [[UIView alloc]initWithFrame:frame];
colorView.layer.cornerRadius = size / 2;
colorView.layer.masksToBounds = YES;
colorView.backgroundColor = ColorDarkGray;
[self.view addSubview:colorView];

现在对我来说,这应该是把视图放在右下角,加上一点填充。但这完全是在屏幕上。我的自动布局关闭了,我只是卡住了。有人能帮我解决这个问题吗。

我知道这个问题已经很老了,但我还是在同样的问题上遇到了麻烦,找到了解决办法

基本上,如果在viewDidLoad或类似文件中读取self.view.frame值,布局似乎还没有完成,因此帧处于关闭状态

尝试覆盖viewWillLayoutSubviews并在[super viewWillLayoutSubviews]之后再次设置框架;-它会起作用的


请注意,在视图中添加视图不会只调用一次,因此可以多次添加视图

注释掉MasktoBoundsId是否检查self.view.frame此时的值?根据您实施此操作的位置,可能是self.view尚未布局。可能您没有使用iPhone肖像模式。是否尝试在ViewWillDisplay中执行此操作?自动布局/自动调整大小?应用了什么规则?Viewwillbehaveit-man。非常感谢。我认为ViewDidLoad是正确的位置,但显然不是。谢谢