iOS掉落回弹效果

//
//  HomePageViewController.m
//  ParkingProject
//
//  Created by Eric on 16/10/13.
//  Copyright © 2016年 Eric. All rights reserved.
//

#import "HomePageViewController.h"

@interface HomePageViewController ()
@property(nonatomic,strong)UIButton *naviButton;
@end

@implementation HomePageViewController
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
   self.naviButton.hidden = YES;
}
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    
      [self handleCASpringAnimation];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.naviButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.naviButton.frame = CGRectMake(kDeviceWidth/2-10,200, 80, 20);
    [self.naviButton setTitle:@"动画" forState:UIControlStateNormal];
    [self.naviButton setBackgroundColor:[UIColor orangeColor]];
    [self.view addSubview:self.naviButton];
   
}
-(void)handleCASpringAnimation{
    CGRect screen = [UIScreen mainScreen].bounds;
    CATransform3D move = CATransform3DIdentity;
    CGFloat initAlertViewYPosition = (CGRectGetHeight(screen) + CGRectGetHeight(_naviButton.frame)) / 2;
    
    move = CATransform3DMakeTranslation(0, -initAlertViewYPosition, 0);
    move = CATransform3DRotate(move, 40 * M_PI/180, 0, 0, 1.0f);
    
    _naviButton.layer.transform = move;
    
    [UIView animateWithDuration:1.0f
                          delay:0.0f
         usingSpringWithDamping:0.4f
          initialSpringVelocity:0.0f
                        options:UIViewAnimationOptionCurveLinear
                     animations:^{
                         self.naviButton.hidden = NO;
                         CATransform3D init = CATransform3DIdentity;
                         _naviButton.layer.transform = init;
                         
                     }
                     completion:^(BOOL finished) {
                     }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self handleCASpringAnimation];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

关键代码如上.

转载于:https://www.cnblogs.com/sunmair/p/5957534.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值