pea*_*pes 5 iphone cocoa objective-c ipad ios
我的应用程序中有很多视图.我想将它们排列成圆形,并根据存在的视图数量改变它们的中心.
所以,如果有3个视图,它们看起来像一个三角形,但仍然会形成一个圆圈.如果有4它看起来像一个正方形但仍然形成一个圆圈,依此类推......
简而言之,所有观点的中心都会坐在一个假想的圆圈上.
有什么建议?
Cra*_*ens 14
这是我在我的一个项目中使用的代码,希望它有所帮助.
// you must set both of these
CGPoint centerOfCircle;
float radius;
int count = 0;
float angleStep = 2.0f * M_PI / [arrayOfViews count];
for (UIView *view in arrayOfViews) {
float xPos = cosf(angleStep * count) * radius;
float yPos = sinf(angleStep * count) * radius;
view.center = CGPointMake(centerOfCircle.x + xPos, centerOfCircle.y +yPos);
count++;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
891 次 |
| 最近记录: |