所以我肯定缺少一些简单的东西,因为我不知道如何移动我的 UIView
这是我目前的情况
我的 .m 文件
- (void)viewDidLoad
{
[super viewDidLoad];
[self buttonLayout];
}
-(void)buttonLayout
{
UIView *theView = [self buttonGroup];
theView.center=CGPointMake(50, 50);
}
我的 .h 文件
@property (nonatomic, retain) IBOutlet UIView *buttonGroup;
这就是我目前所拥有的,我似乎根本无法让它移动 P.S 我不希望它动画化,因为我正在移动我的布局以补偿不同的 iPhone 屏幕尺寸:)
最佳答案
我还没有测试过这个,但看起来你需要:
A) 从其父 View 中删除 View 。
B) 调整其“框架”的中心,而不是 View 。
C) 重新添加 subview 。
像这样:
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];
这应该适用于 自动布局。
关于ios - UIView 不会以编程方式移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22949568/