//联系人:石虎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"
@interfaceViewController()
@property(nonatomic,strong)UIImageView*testView;
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
//创建移动视图
_testView=[[UIImageViewalloc]init];
_testView.frame=CGRectMake(0,200,100,100);
_testView.backgroundColor=[UIColororangeColor];
[self.viewaddSubview:_testView];
//创建功能按钮
NSArray*array=@[@"缩放",@"弹性",@"平移"];
for(inti =0; i
UIButton*btn=[UIButtonbuttonWithType:UIButtonTypeCustom];
btn.frame=CGRectMake(10+60*i,500,50,40);
btn.tag=i+1;
btn.backgroundColor=[UIColorredColor];
[btnsetTitle:array[i]forState:UIControlStateNormal];
[btnsetTitleColor:[UIColorblackColor]forState:UIControlStateNormal];
[btnaddTarget: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:^(BOOLfinished) {
[UIViewanimateWithDuration:0.23delay:0options:UIViewAnimationOptionCurveEaseInOutanimations:^{
[_testView.layersetValue:@(1.2)forKeyPath:@"transform.scale"];
}completion:^(BOOLfinished) {
[UIViewanimateWithDuration:0.09delay:0.02options:UIViewAnimationOptionCurveEaseInOutanimations:^{
[_testView.layersetValue:@(.9)forKeyPath:@"transform.scale"];
}completion:^(BOOLfinished) {
[UIViewanimateWithDuration:0.05delay:0.02options:UIViewAnimationOptionCurveEaseInOutanimations:^{
[_testView.layersetValue:@(1.0)forKeyPath:@"transform.scale"];
}completion:^(BOOLfinished) {
}];}];}];}];
[UIViewanimateWithDuration:.3delay:0options:UIViewAnimationOptionCurveEaseInOutanimations:^{
[btn.layersetValue:@(1.3)forKeyPath:@"transform.scale"];
}completion:^(BOOLfinished) {
[UIViewanimateWithDuration:.3delay:0options:UIViewAnimationOptionCurveEaseInOutanimations:^{
[btn.layersetValue:@(1.0)forKeyPath:@"transform.scale"];
}completion:^(BOOLfinished) {}];}];}
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:^(BOOLfinished) {}];}
break;
case3://平移
{
[_testView.layersetValue:@(50)forKeyPath:@"position.x"];
[UIViewanimateWithDuration:1.3animations:^{
[_testView.layersetValue:@(150)forKeyPath:@"position.x"];
}completion:^(BOOLfinished) {}];}
break;
default:
break;}}
@end
================
=======
谢谢!!!