View的放大->旋轉->還原動畫,view動畫

來源:互聯網
上載者:User

View的放大->旋轉->還原動畫,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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.