实现原理是改变view的角度,非常简单,直接上码!但不是很完美,有时间加上 重力行为(UIGravityBehavior)。
- (IBAction)ButtonAction:(id)sender {
__block UIView *alertView = [[UIView alloc]init];
alertView.backgroundColor = [UIColor greenColor];
// 跌落前的坐标
alertView.frame =CGRectMake(self.view.frame.size.width/2-100, -self.view.frame.size.height/2-100,200,200);
[self.viewaddSubview:alertView];
// 跌落后的坐标
CGRect afterDropFrame =CGRectMake(self.view.frame.size.width/2-100,self.view.frame.size.height/2-100,200,200);
//设置旋转角度
alertView.transform =CGAffineTransformMakeRotation(-M_1_PI);
[UIViewanimateWithDuration: 0.5 delay:0.2 options:UIViewAnimationOptionCurveEaseInanimations:^{
//跌落后设置旋转角度0
alertView.transform =CGAffineTransformMakeRotation(0);
alertView.frame = afterDropFrame;
} completion:^(BOOL finished) {
}];
}