我无法理解如何从第二个UIView
的中心开始向UIView
添加UIView
而不是左上角,我正在制作一个例子:
我想为此UIView
添加CGPoint
:( - 96,96),第二个UIView
它是一个方形矩形300x300,所以我想从{1}开始添加UIView
中心,而是从左上角开始添加UIVIew
,当它被添加到屏幕外时,这是一个例子:
________________
| |
y | x |
| . |
| |
| |
|______________|
x = where i want should go the UIView
y = where instead it's added
我怎么能解决它?
编辑: 我以这种方式添加UIView:
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 70, 70)];
v.center = CGPointMake(-96,96);
[self.squareView addSubview:v];
答案 0 :(得分:0)
试试这个:
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 70, 70)];
v.center = squareView.center;
var frame:CGRect = v.frame
frame.origin.x -= 96
frame.origin.y += 96
v.frame = frame
[self.squareView addSubview:v];