View的放大->旋转->还原动画_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > View的放大->旋转->还原动画

View的放大->旋转->还原动画

 2017/10/11 16:43:10  风吹,风筝在飞  程序员俱乐部  我要评论(0)
  • 摘要:以UIButton为例,创建一个类,继承于UIButton/*页面的创建用storyboard*/.h文件@interfacePTSRecommendButton:UIButton-(void)viewTransform;@end.m文件@implementationPTSRecommendButton-(void)viewTransform{//[self.layersetAnchorPoint:CGPointMake(1,0.5)];CGRectbtnFrame=self.frame
  • 标签:view

以UIButton为例,创建一个类,继承于UIButton 

/*页面的创建用storyboard*/

 .h文件             

@interface PTSRecommendButton : UIButton

- (void)viewTransform;

@end

.m文件

@implementation PTSRecommendButton

- (void)viewTransform {

    //

    [self.layer setAnchorPoint:CGPointMake(1, 0.5)];

    CGRect btnFrame = self.frame;

    //设置中心点  AnchorPoint默认是0.5

    btnFrame.origin.x += btnFrame.size.width / 2 ;

    self.frame = btnFrame;

    //放大

    [UIView transitionWithView:self duration:0.5 options:UIViewAnimationOptionAllowUserInteraction animations:^{

   //因为是button在动画之行的过程点击如果没有页面跳转的操作。要设置不能狗被点击 否则会引起动画方法的覆盖 

        //self.userInteractionEnabled = NO;  

        self.transform = CGAffineTransformMakeScale(1.2, 1.2);

    } completion:^(BOOL finished) {

        //还原中心点

        [self.layer setAnchorPoint:CGPointMake(0.5, 0.5)];

        CGRect btnFrame = self.frame;

        btnFrame.origin.x -= btnFrame.size.width / 2 ;

        self.frame = btnFrame;

        //旋转

        [UIView transitionWithView:self duration:0.25 options:UIViewAnimationOptionAllowUserInteraction animations:^{

            //

            self.transform = CGAffineTransformRotate(self.transform, M_PI*0.05);

        } completion:^(BOOL finished) {

            //反向旋转

            [UIView transitionWithView:self duration:0.5 options:UIViewAnimationOptionAllowUserInteraction animations:^{

                self.transform = CGAffineTransformRotate(self.transform, -M_PI*0.1);

            } completion:^(BOOL finished) {

                //回到最初旋转状态

                [UIView transitionWithView:self duration:0.25 options:UIViewAnimationOptionAllowUserInteraction animations:^{

                    self.transform = CGAffineTransformRotate(self.transform, M_PI*0.05);

                } completion:^(BOOL finished) {

                    //中心点还原

                    [self.layer setAnchorPoint:CGPointMake(1, 0.5)];

                    CGRect btnFrame = self.frame;

                    btnFrame.origin.x += btnFrame.size.width / 2 ;

                    self.frame = btnFrame;

                    //恢复初始的状态

                    [UIView transitionWithView:self duration:0.5 options:UIViewAnimationOptionAllowUserInteraction animations:^{

                        self.transform = CGAffineTransformIdentity;

                    } completion:^(BOOL finished) {

                        [self.layer setAnchorPoint:CGPointMake(.5, 0.5)];

                        CGRect btnFrame = self.frame;

                        //设置中心点  AnchorPoint默认是0.5

                        btnFrame.origin.x -= btnFrame.size.width / 2 ;

                        self.frame = btnFrame;

                        //self.userInteractionEnabled = YES ;

                    }];

                }];

            }];

        }];

    }];

}

@end

发表评论
用户名: 匿名