iOS TranslationZoom(平移 缩放 弹性)~demo

//联系人:石虎  QQ: 1224614774昵称:嗡嘛呢叭咪哄

/**

注意点: 1.看 GIF 效果图.

       2.看连线视图的效果图.

       3.看实现代码(直接复制实现效果).

*/

一、GIF 效果图:



二、连线视图的效果图:

图1:




三、实现代码:

=========================

===================================================

==========================

控制器1: ViewController.m

//

//  ViewController.m

//  TranslationZoom(平移缩放弹性)~demo

//

//  Created by 石虎 on 2017/8/19.

//  Copyright © 2017 shihu. All rights reserved.

//


#import "ViewController.h"


@interface ViewController ()


@property (nonatomic,strong)UIImageView *testView;

@end


@implementation ViewController


- (void)viewDidLoad {

    [superviewDidLoad];


    //创建移动视图

    _testView=[[UIImageViewalloc] init];

    _testView.frame=CGRectMake(0,200, 100,100);

    _testView.backgroundColor=[UIColororangeColor];

    [self.viewaddSubview:_testView];

    

    //创建功能按钮

    NSArray *array=@[@"缩放",@"弹性",@"平移"];

    for (int i =0; i<array.count; i++) {

        UIButton *btn=[UIButtonbuttonWithType:UIButtonTypeCustom];

        btn.frame=CGRectMake(10+60*i,500, 50,40);

        btn.tag=i+1;

        btn.backgroundColor=[UIColorredColor];

        [btn setTitle:array[i]forState:UIControlStateNormal];

        [btn setTitleColor:[UIColorblackColor] forState:UIControlStateNormal];

        [btn addTarget:selfaction:@selector(startAnimation:)forControlEvents:UIControlEventTouchUpInside];

        [self.viewaddSubview:btn];

    }

}


#pragma mark - 缩放弹性平移功能回调

-(void)startAnimation:(UIButton *)btn{

    _testView.transform=CGAffineTransformIdentity;

    switch (btn.tag) {

        case1://缩放

        {

            

            

            [UIViewanimateWithDuration:0delay:0options:UIViewAnimationOptionCurveEaseInOutanimations:^{

                [_testView.layersetValue:@(0.1)forKeyPath:@"transform.scale"];

                

            } completion:^(BOOL finished) {

                [UIViewanimateWithDuration:0.23delay:0options:UIViewAnimationOptionCurveEaseInOutanimations:^{

                    [_testView.layersetValue:@(1.2)forKeyPath:@"transform.scale"];

                    

                } completion:^(BOOL finished) {

                    [UIViewanimateWithDuration:0.09delay:0.02options:UIViewAnimationOptionCurveEaseInOutanimations:^{

                        [_testView.layersetValue:@(.9)forKeyPath:@"transform.scale"];

                        

                    } completion:^(BOOL finished) {

                        [UIViewanimateWithDuration:0.05delay:0.02options:UIViewAnimationOptionCurveEaseInOutanimations:^{

                            [_testView.layersetValue:@(1.0)forKeyPath:@"transform.scale"];

                            

                        } completion:^(BOOL finished) {

                            

                        }];

                    }];

                }];

            }];

            

            

            [UIViewanimateWithDuration:.3delay:0options:UIViewAnimationOptionCurveEaseInOutanimations:^{

                

                [btn.layersetValue:@(1.3)forKeyPath:@"transform.scale"];

            } completion:^(BOOL finished) {

                [UIViewanimateWithDuration:.3delay:0options:UIViewAnimationOptionCurveEaseInOutanimations:^{

                    

                    [btn.layersetValue:@(1.0)forKeyPath:@"transform.scale"];

                } completion:^(BOOL finished) {

                    

                }];

            }];

 

        }

            break;

            

        case2://弹性

        {

            //Damping 弹性,0-1,越小弹性越大

            //Velocity 弹性复位速度

            [_testView.layersetValue:@(0)forKeyPath:@"transform.translation.x"];

            [UIViewanimateWithDuration:.6delay:0usingSpringWithDamping:.3initialSpringVelocity:.5options:UIViewAnimationOptionCurveEaseInOutanimations:^{

                

                [_testView.layersetValue:@(150)forKeyPath:@"transform.translation.x"];

            } completion:^(BOOL finished) {

                

            }];

            

            

        }

            break;

            

        case3://平移

        {

            

            

            [_testView.layersetValue:@(50)forKeyPath:@"position.x"];

            [UIViewanimateWithDuration:1.3animations:^{

                [_testView.layersetValue:@(150)forKeyPath:@"position.x"];

            } completion:^(BOOL finished) {

                

            }];

            

        }

            break;

            

        default:

            break;

    }    

}

@end



================

=======



谢谢!!!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值