**第一次写博客有点激动呢**
使用 UIDynamic 的方法就不叙述了
这里先讲一下 牛顿摆是经过计算的一个公式才能达到理想状态 由于我不知道公式 所以做出来不能完美的达成 一个小球落下来另一个小球飞起来
接下来直接上代码 代码中的描述还是很详细的
#import "ViewController.h"
#import "ContentView.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
ContentView *view =[[ContentView alloc]initWithFrame:self.view.bounds];
view.backgroundColor=[UIColor blueColor];
[self.view addSubview:view];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
#import "ContentView.h"
#import "BallsView.h"
@interface ContentView(){
UIDynamicAnimator *_animator;//仿真模拟器
NSMutableArray *_arrayBalls;
CGPoint _centers[100];//可变的小球中心坐标
UISnapBehavior *_snapB;
UIAttachmentBehavior *attachement1;
}
@end
static CGFloat radius=20;//小球半径
static