让一个正方形View以四个角中的任意一角为起点放大或缩小
2016-03-01 11:40
513 查看
之前一直想要做这样的效果,结果昨晚无意间就弄出了大致的样子,今天对代码进行了调整,下面是最终的效果。
//缩放比例
#define kDistance 1.5
typedef enum{
BeginPointTypeLeftTop = 0,
BeginPointTypeLeftBottom,
BeginPointTypeRightTop,
BeginPointTypeRightBottom,
}BeginPointType;
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[selfrunAnimationChangeBigWithView:self.redViewbeginPointType:BeginPointTypeLeftTop];
[selfrunAnimationChangeBigWithView:self.orangeViewbeginPointType:BeginPointTypeRightBottom];
[selfrunAnimationChangeBigWithView:self.blueViewbeginPointType:BeginPointTypeLeftBottom];
[selfrunAnimationChangeBigWithView:self.greenViewbeginPointType:BeginPointTypeRightTop];
[selfrunAnimationChangeSmallWithView:self.redView1beginPointType:BeginPointTypeLeftTop];
[selfrunAnimationChangeSmallWithView:self.orangeView1beginPointType:BeginPointTypeRightBottom];
[selfrunAnimationChangeSmallWithView:self.blueView1beginPointType:BeginPointTypeLeftBottom];
[selfrunAnimationChangeSmallWithView:self.greenView1beginPointType:BeginPointTypeRightTop];
}
/**
* 放大
*/
-(void)runAnimationChangeBigWithView:(UIView *)view beginPointType:(BeginPointType)beginPointType
{
[UIViewanimateWithDuration:3.fdelay:0options:UIViewAnimationOptionRepeat
|UIViewAnimationOptionAutoreverse animations:^{
CGRect frame = view.frame;
frame.size.width *=kDistance;
frame.size.height *=kDistance;
switch (beginPointType) {
caseBeginPointTypeLeftBottom:
frame.origin.y -= frame.size.height - frame.size.height
/ kDistance;
break;
caseBeginPointTypeRightTop:
frame.origin.x -= frame.size.width - frame.size.width
/ kDistance;
break;
caseBeginPointTypeRightBottom:
frame.origin.x -= frame.size.width - frame.size.width
/ kDistance;
frame.origin.y -= frame.size.height - frame.size.height
/ kDistance;
break;
default:
break;
}
[view setFrame:frame];
} completion:nil];
}
/**
* 缩小
*/
-(void)runAnimationChangeSmallWithView:(UIView *)view beginPointType:(BeginPointType)beginPointType
{
[UIViewanimateWithDuration:3.fdelay:0options:UIViewAnimationOptionRepeat
|UIViewAnimationOptionAutoreverse animations:^{
CGRect frame = view.frame;
frame.size.width /=kDistance;
frame.size.height /=kDistance;
switch (beginPointType) {
caseBeginPointTypeLeftBottom:
frame.origin.y -= frame.size.height - frame.size.height
* kDistance;
break;
caseBeginPointTypeRightTop:
frame.origin.x -= frame.size.width - frame.size.width
* kDistance;
break;
caseBeginPointTypeRightBottom:
frame.origin.x -= frame.size.width - frame.size.width
* kDistance;
frame.origin.y -= frame.size.height - frame.size.height
* kDistance;
break;
default:
break;
}
[view setFrame:frame];
} completion:nil];
}
//缩放比例
#define kDistance 1.5
typedef enum{
BeginPointTypeLeftTop = 0,
BeginPointTypeLeftBottom,
BeginPointTypeRightTop,
BeginPointTypeRightBottom,
}BeginPointType;
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[selfrunAnimationChangeBigWithView:self.redViewbeginPointType:BeginPointTypeLeftTop];
[selfrunAnimationChangeBigWithView:self.orangeViewbeginPointType:BeginPointTypeRightBottom];
[selfrunAnimationChangeBigWithView:self.blueViewbeginPointType:BeginPointTypeLeftBottom];
[selfrunAnimationChangeBigWithView:self.greenViewbeginPointType:BeginPointTypeRightTop];
[selfrunAnimationChangeSmallWithView:self.redView1beginPointType:BeginPointTypeLeftTop];
[selfrunAnimationChangeSmallWithView:self.orangeView1beginPointType:BeginPointTypeRightBottom];
[selfrunAnimationChangeSmallWithView:self.blueView1beginPointType:BeginPointTypeLeftBottom];
[selfrunAnimationChangeSmallWithView:self.greenView1beginPointType:BeginPointTypeRightTop];
}
/**
* 放大
*/
-(void)runAnimationChangeBigWithView:(UIView *)view beginPointType:(BeginPointType)beginPointType
{
[UIViewanimateWithDuration:3.fdelay:0options:UIViewAnimationOptionRepeat
|UIViewAnimationOptionAutoreverse animations:^{
CGRect frame = view.frame;
frame.size.width *=kDistance;
frame.size.height *=kDistance;
switch (beginPointType) {
caseBeginPointTypeLeftBottom:
frame.origin.y -= frame.size.height - frame.size.height
/ kDistance;
break;
caseBeginPointTypeRightTop:
frame.origin.x -= frame.size.width - frame.size.width
/ kDistance;
break;
caseBeginPointTypeRightBottom:
frame.origin.x -= frame.size.width - frame.size.width
/ kDistance;
frame.origin.y -= frame.size.height - frame.size.height
/ kDistance;
break;
default:
break;
}
[view setFrame:frame];
} completion:nil];
}
/**
* 缩小
*/
-(void)runAnimationChangeSmallWithView:(UIView *)view beginPointType:(BeginPointType)beginPointType
{
[UIViewanimateWithDuration:3.fdelay:0options:UIViewAnimationOptionRepeat
|UIViewAnimationOptionAutoreverse animations:^{
CGRect frame = view.frame;
frame.size.width /=kDistance;
frame.size.height /=kDistance;
switch (beginPointType) {
caseBeginPointTypeLeftBottom:
frame.origin.y -= frame.size.height - frame.size.height
* kDistance;
break;
caseBeginPointTypeRightTop:
frame.origin.x -= frame.size.width - frame.size.width
* kDistance;
break;
caseBeginPointTypeRightBottom:
frame.origin.x -= frame.size.width - frame.size.width
* kDistance;
frame.origin.y -= frame.size.height - frame.size.height
* kDistance;
break;
default:
break;
}
[view setFrame:frame];
} completion:nil];
}
相关文章推荐
- Android开发之图形图像与动画(二)Animation实现图像的渐变/缩放/位移/旋转
- Android开发重写Animation实现下拉图片后弹射回去效果示例
- Android编程之Animation动画详解
- Android Animation实战之屏幕底部弹出PopupWindow
- Android Animation实战之一个APP的ListView的动画效果
- How to delete all the animations in a presentation
- Transform/Transition/Animation的区别与联系
- HTML前端开发之路——Animation
- Android 应用的动画实践--View Animation篇
- angular.animation的使用
- IOS中常用动画方法总结
- Qt-4.6动画Animation快速入门三字决
- 研究一下Android中的动画效果
- 自定义dialog--symbian
- 乔布斯在2005年斯坦福大学毕业典礼上的演讲:我生命中的三个故事
- Android 移动动画- TranslateAnimation
- 通天塔
- (译)Cocos2d_for_iPhone_1_Game_Development_Cookbook:1.12使用层来交换调色板
- Blender 3D渲染工具