ios中的各中動畫(旋轉,平移)

來源:互聯網
上載者:User


//圖片進行自動旋轉

CABasicAnimation是一個最多隻能有兩個主要畫面格的動畫,

UIImageView *imageView = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"7"]];

imageView.frame =CGRectMake(40, 60,200, 250);

[self.viewaddSubview:imageView];

CABasicAnimation *animation = [CABasicAnimationanimationWithKeyPath:@"transform"];

animation.delegate =self;

animation.toValue = [NSValuevalueWithCATransform3D:CATransform3DMakeRotation(M_PI,0, 0,1.0)];

//執行時間

animation.duration =30;

animation.cumulative =YES;//累積的

//執行次數

animation.repeatCount = INT_MAX;

animation.autoreverses=YES;//是否自動重複

[imageView.layeraddAnimation:animation forKey:@"animation"];


通過CATransition實作類別似UINavigationController的pushview及Popview效果

CATransition動畫使用了類型type和子類型subtype兩個概念。type屬性指定了過渡的種類(淡化、推擠、揭開、覆蓋)。subtype設定了過渡的方向(從上、下、左、右)。另外,CATransition私人的動畫類型有(立方體、吸收、翻轉、波紋、翻頁、反翻頁、鏡頭開、鏡頭關)。


/* CATransition *myT = [ CATransition animation];

myT.timingFunction = UIViewAnimationCurveEaseInOut;

myT.type = @"cube";

//動畫類型

// 1 kCATransitionFromBottom

// 2 kCATransitionFromLeft

// 3 kCATransitionFromTop

// 4 kCATransitionFromRight

//myT.subtype = kCATransitionFromLeft;

myT.subtype = kCATransitionFromLeft;

myT.duration = 0.5;

[self.navigationController.view.layer addAnimation: myT forKey:nil];

NSLog(@"app");*/


建立UIView動畫(塊)——(指過渡效果的動畫)


//方法一:

//過度動畫的效果,是2個View的切換

- (void)viewDidLoad

{

[superviewDidLoad];


UIButton* button12 = [[UIButtonalloc]initWithFrame:CGRectMake(20,340, 150, 30)];

[button12 addTarget:self action:@selector(button22)forControlEvents:UIControlEventTouchUpInside];

[button12 setTitle:@"開始動畫" forState:UIControlStateNormal];

button12.backgroundColor = [UIColorredColor];

[self.viewaddSubview:button12];

//方法二:

// 2 用block文法實現

/* [UIView animateWithDuration:0.5 animations:^{

CGRect frames = self.view_1.frame;

frames.origin.x = 160;

self.view_1.frame = frames;

//縮放

self.view_1.transform = CGAffineTransformScale(self.view_1.transform, 0.01, 0.01);

}completion:^(BOOL finished) {

CGRect frames = self.view_1.frame;

frames.origin.x = 0;

self.view_1.frame = frames;

//恢複到原始的縮放

self.view_1.transform = CGAffineTransformIdentity;

}];*/

}


-(void)button22

{

//開始動畫

[UIViewbeginAnimations:@"testanimation"context:nil];

[UIViewsetAnimationDuration:0.5];

//代理

[UIViewsetAnimationDelegate:self];

//動畫的響應事件,使視圖自動回到原來的位置

[UIViewsetAnimationDidStopSelector:@selector(animationstop)];

[UIViewsetAnimationCurve:UIViewAnimationCurveEaseInOut];

//獲得視圖的位置

CGRect frames =self.view_1.frame;

frames.origin.x =160;

self.view_1.frame = frames;

[UIViewcommitAnimations];

}


-(void)animationstop

{

[UIViewbeginAnimations:nilcontext:nil];

[UIViewsetAnimationDuration:0.5];

CGRect frames =self.view_1.frame;

frames.origin.x =0;

self.view_1.frame = frames;

[UIViewcommitAnimations];

}




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.