您的位置:首页 > 产品设计 > UI/UE

让一个正方形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];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  uivew animation