因此我必须有一些简单的东西,因为我无法弄清楚如何移动我的UIView
这就是我到目前为止所拥有的
我的.m文件
- (void)viewDidLoad
{
[super viewDidLoad];
[self buttonLayout];
}
-(void)buttonLayout
{
UIView *theView = [self buttonGroup];
theView.center=CGPointMake(50, 50);
}
Run Code Online (Sandbox Code Playgroud)
我的.h文件
@property (nonatomic, retain) IBOutlet UIView *buttonGroup;
Run Code Online (Sandbox Code Playgroud)
所以这就是我到目前为止,我只是似乎无法让它移动到所有PS我不希望它动画,因为我让我的布局移动,以弥补不同的iPhone屏幕尺寸:)
正如另一张海报所说,当你有效地进行自动布局时,你不能通过改变它们的中心或框架来移动视图.
相反,您必须添加一个垂直和水平约束,从顶部/左边定位视图,将出口连接到约束,然后从代码更改约束的常量值.
我没有测试过这个,但似乎你需要:
A)从其父级中删除视图.
B)调整"框架"的中心,而不是视图.
C)重新添加子视图.
像这样:
UIView *theView = [self buttonGroup];
CGRect theFrame = theView.frame;
[theView removeFromSuperview];
theFrame.origin.x = 50.0;
theFrame.origin.y = 50.0;
theView.frame = theFrame;
[self.view addSubview:theView];
Run Code Online (Sandbox Code Playgroud)
这应该适用于 autolayout.
| 归档时间: |
|
| 查看次数: |
5058 次 |
| 最近记录: |