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