IOS之 基本動畫原理

來源:互聯網
上載者:User

IOS動畫分為屬性動畫和過渡動畫。ios4.0之前

屬性動畫

內容和設定主要放在方括弧中既:如下

[UIView beginAnimations:@move context:@aa];

中間部分設定動畫內容和屬性

[UIView commitAnimations];

詳見代碼如下

    [UIView beginAnimations:@move context:@aa];    [UIView setAnimationDuration:1];//設定動畫時間    CGPoint point = self.View1.center;//    [UIView setAnimationDelegate:self];//設定代理    [UIView setAnimationWillStartSelector:@selector(startAnimation:)];//動畫開始之前    [UIView setAnimationDidStopSelector:@selector(stopAnition:)];//動畫結束之後    //    [UIView setAnimationRepeatAutoreverses:YES];    self.View1.center = CGPointMake(point.x+1, point.y);//    self.View1.backgroundColor = [UIColor orangeColor];    [UIView commitAnimations];

一下是能夠設定屬性動畫的屬性:

 

The following properties of the UIView class are animatable:

@property frame
@property bounds
@property center
@property transform
@property alpha
@property backgroundColor
@property contentStretch

過渡動畫:

 

    [UIView beginAnimations:@move context:@text];    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.View3 cache:YES];        [UIView commitAnimations];

能夠設定的屬性:

 

typedef NS_ENUM(NSInteger, UIViewAnimationTransition) {
UIViewAnimationTransitionNone,
UIViewAnimationTransitionFlipFromLeft,
UIViewAnimationTransitionFlipFromRight,
UIViewAnimationTransitionCurlUp,
UIViewAnimationTransitionCurlDown,
};

 

4.0之後修改為調用block

Animating Views with Block Objects

//屬性動畫

+ animateWithDuration:delay:options:animations:completion:
+ animateWithDuration:animations:completion:
+ animateWithDuration:animations:

//過渡動畫

+ transitionWithView:duration:options:animations:completion:
+ transitionFromView:toView:duration:options:completion:

//主要畫面格動畫
+ animateKeyframesWithDuration:delay:options:animations:completion:
+ addKeyframeWithRelativeStartTime:relativeDuration:animations:

//系統動畫
+ performSystemAnimation:onViews:options:animations:completion:

//未知,還為測試
+ animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:
+ performWithoutAnimation:

 

 

CAAnimation動畫

代碼如下:具體過程。

 

    //CABasicAnimation 動畫        CABasicAnimation* baseAnimation = [CABasicAnimation animationWithKeyPath:@center];    baseAnimation.fromValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 0, 0)];        baseAnimation.fromValue = [NSValue valueWithCGPoint:CGPointMake(400, 100)] ;    baseAnimation.duration = 3;    [self.View2.layer addAnimation:baseAnimation forKey:@baseAnimation];    // CAKeyframeAnimation 動畫    CAKeyframeAnimation* keyAnimation = [CAKeyframeAnimation animationWithKeyPath:@position];    keyAnimation.values =[NSArray arrayWithObjects:                          [NSValue valueWithCGPoint:CGPointMake(self.View2.center.x+5, self.View2.center.y)],                          [NSValue valueWithCGPoint:CGPointMake(self.View2.center.x, self.View2.center.y)],                          [NSValue valueWithCGPoint:CGPointMake(self.View2.center.x-5, self.View2.center.y)],                          [NSValue valueWithCGPoint:CGPointMake(self.View2.center.x, self.View2.center.y)],                          [NSValue valueWithCGPoint:CGPointMake(self.View2.center.x+5, self.View2.center.y)],                          [NSValue valueWithCGPoint:CGPointMake(self.View2.center.x, self.View2.center.y)],                          nil];    keyAnimation.keyTimes = @[[NSNumber numberWithFloat:.1],                              [NSNumber numberWithFloat:.2],                              [NSNumber numberWithFloat:.3],                              [NSNumber numberWithFloat:.4],                              [NSNumber numberWithFloat:.5],                              [NSNumber numberWithFloat:1]];//設定時間 ,百分比    keyAnimation.calculationMode = kCAAnimationDiscrete;    [self.View2.layer addAnimation:keyAnimation forKey:@position];    //CATransition 動畫     CATransition* transiton = [CATransition animation];    transiton.startProgress = 0;    transiton.endProgress = 1.0;    transiton.duration = 3;    transiton.type = kCATransitionReveal;//根據不同值顯示不同動畫    transiton.subtype = kCATransitionFromRight;    [self.view.layer addAnimation:transiton forKey:@transtion];


聯繫我們

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