我不确定这是否可行,但我想要做的是将一个子视图多次添加到父视图中。我已经尝试了类似于以下的代码:
[self.view addSubview: newView];
newView.center = CGPointMake(160, 100);
[self.view addSubview: newView];
newView.center = CGPointMake(160, 200);
[self.view addSubview: newView];
这只是将newView
移动,而不是添加新的视图。有什么想法吗?
我也尝试了这个:
[self.view addSubview:newView];
UIView *anotherView = newView;
anotherView.center = CGPointMake(160, 100)
[self.view addSubview:anotherView];
编辑
这是我随着时间逐渐学会的解决方案。
另一个解决该问题的方法是创建一个包含视图的单独的nib文件,并多次添加nib的实例。一个实现此解决方案的良好模板是以与在cellForRowAtIndexPath
方法中使用自定义UITableViewCell
相同的方式进行。