之前一直想要做这样的效果,结果昨晚无意间就弄出了大致的样子,今天对代码进行了调整,下面是最终的效果。
//缩放比例
#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];
}