亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

Animation Types

系統 2602 0

3.1 Basic Animation

?

?CABasicAnimation

?

3.2 Keyframe Animations

?

我最近進行了一些關于關鍵楨動畫方面的研究,感覺不錯。關鍵楨動畫其實是一個很酷的東西,因為它們會在你創建的層進行動作時給你提供更加精確的控制?;緞赢嬙凇伴_始”和“結束”點之間進行線性插值,在很多情況下,你都可以使用基本動畫。但是有時候,如果你希望進行一些不一樣或者更復雜的動畫時,基本動畫就不夠用了。本文介紹的關鍵楨動畫可以允許你在動畫的過程中進行精確控制。


與基本動畫進行線性插值不同,關鍵楨動畫允許你在特定時間指定不同的數值,這樣你可以在動畫的全過程控制動畫的展示和動作。


自從發明手繪電影以來,關鍵楨就在動畫中起到了一定作用。一些資深的藝術家會針對一個場景畫不同的關鍵楨,而一些剛入行的藝術家卻會填滿每一楨,以便使動畫看起來更平滑。(有時候這個過程叫做tweening:兩者之間的動畫)。Core Animation的關鍵楨動畫可以幫我們實現在關鍵楨之間的填充,我們只需要指定哪個是關鍵楨,系統會自動幫我們生成動畫。


另外一個很酷的東西是,關鍵楨動畫同樣可以完成任何基本動畫能夠完成的動作。特別是點、大小或是矩形。比如如果我們希望讓一個層的不透明度顯示為一個動畫,我們可以指定一些不同的數值(比如:0.25, 0.50, 0.75),然后在動畫的過程的不同時間中逐漸變化。


再一個真的很酷的方面,我們不光可以使用離散數值,更可以使用CGPath去指定關鍵楨動畫的值。換句話說,我們不僅僅可以在特定時間點指定特定的動畫值,還可以使用曲線路徑去指定動畫的值。舉例說明,我們可以將一個層的不透明度用鐘型曲線表示:開始是透明,然后逐漸顯現到某個特定透明度,再逐漸變為透明。我們還可以用CGPoint和CGSize值的路徑做為動畫的行進路線。這樣,路徑的x值可以表示橫坐標也可以表示寬度,y既可以表示縱坐標還可以表示高度。

?

?

?

寫道
Keyframes are specified by providing an array of values, one value for each specific keyframe we want to set during the animation.

?

寫道
Another important thing to keep in mind about keyframe animations is that they work in terms of “normalized” time.

?

寫道
Another important thing to keep in mind about keyframe animations is that they work in terms of “normalized” time.

?

The code to create the keyframe animation would look like this:

?

    - (CAKeyframeAnimation *)opacityAnimation {
CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
animation.values = [NSArray arrayWithObjects:
                                         [NSNumber numberWithFloat:0.0],
                                         [NSNumber numberWithFloat:0.75],
                                         [NSNumber numberWithFloat:0.0], nil];

animation.keyTimes = [NSArray arrayWithObjects:
                                           [NSNumber numberWithFloat:0.25],
                                           [NSNumber numberWithFloat:0.50],
                                           [NSNumber numberWithFloat:0.75], nil];
        return animation;
}
  

?

不設置keyTimes時的運行方式:

If we leave out setting the time values, the keyframe animation will just evenly distribute the values we provide over the time frame.
If we provide three values, the first value is the starting value, the second value will be reached at 50% of the elapsed time, and the third value is at 100% of the time.

?

?

Keyframes and Paths

?

Animation Types

?

    - (void)addBounceAnimation {
  [mover setAnimations:[NSDictionary dictionaryWithObjectsAndKeys:
  self.originAnimation, @"frameOrigin" , nil]];
  }

- (id)initWithFrame:(NSRect)frame {
          self = [super initWithFrame:frame];
       if (self) {
       CGFloat xInset = 3.0f * (NSWidth(frame) / 8.0f);
       CGFloat yInset = 3.0f * (NSHeight(frame) / 8.0f);
       NSRect moverFrame = NSInsetRect(frame, xInset, yInset);
       mover = [[NSImageView alloc] initWithFrame:moverFrame];
       [mover setImageScaling:NSScaleToFit];
       [mover setImage:[NSImage imageNamed:@"photo.jpg" ]];
       [self addSubview:mover];
       [self addBounceAnimation];
  }
      return self;
 }
  

?

?

[mover setAnimations:[NSDictionary dictionaryWithObjectsAndKeys:?self.originAnimation, @" frameOrigin " , nil]];

?

frameOrigin:

這個動畫的key
要和[[mover animator] setFrameOrigin:rect.origin];的
setFrameOrigin相對應,才會在setFrameOrigin方法被調用的時候,執行設置的動畫

例如:
- (void)awakeFromNib

{

NSView *contentView = [[self window] contentView];

[contentView setWantsLayer:YES];

[contentView addSubview:[self currentView]];

transition = [CATransition animation];

[transition setType:kCATransitionPush];

[transition setSubtype:kCATransitionFromLeft];

NSDictionary *ani = [NSDictionary dictionaryWithObject:transition
forKey:@"subviews"];
[contentView setAnimations:ani];

}

awakeFromNib首先打開Core Animation支持(就是setWantsLayer這行)。然后把當前的參考視圖currentView做為子視圖加入到contentView中。由于我們已經將currentView的frameOrigin屬性設置為0,0,因此不需要考慮subview的位置。

接下來我建立了一個CATransition的動畫。注意我在AppDelegate中將這個動畫保留為ivar。原因很明顯,當動畫建立時,我將它做為transition動畫加入content view,key是“subviews”。這個transition動畫無論在一個subview添加、刪除或者替換的時候都會觸發。

?

    - (CAKeyframeAnimation *)originAnimation {
CAKeyframeAnimation *originAnimation = [CAKeyframeAnimation animation];
     originAnimation.path = self.heartPath;
     originAnimation.duration = 2.0f;
     originAnimation.calculationMode = kCAAnimationPaced;
     return originAnimation;
 }
  

?

設置動畫運行路徑:

???? originAnimation.path = self.heartPath;

設置動畫持續時間:

???? originAnimation.duration = 2.0f;

設置動畫方式:
???? originAnimation.calculationMode = kCAAnimationPaced;

?

?

設置動畫路徑:

    - (CGPathRef)heartPath {
      NSRect frame = [mover frame];
if(heartPath == NULL) {
              heartPath = CGPathCreateMutable();
             CGPathMoveToPoint(heartPath, NULL, NSMinX(frame), NSMinY(frame));
             CGPathAddLineToPoint(heartPath, NULL, NSMinX(frame) - NSWidth(frame),NSMinY(frame) + NSHeight(frame) * 0.85);
             CGPathAddLineToPoint(heartPath, NULL, NSMinX(frame),NSMinY(frame) - NSHeight(frame) * 1.5);
             CGPathAddLineToPoint(heartPath, NULL, NSMinX(frame) + NSWidth(frame),NSMinY(frame) + NSHeight(frame) * 0.85);
             CGPathAddLineToPoint(heartPath, NULL, NSMinX(frame), NSMinY(frame));
             CGPathCloseSubpath(heartPath);
}
       return heartPath;
}
  

?

這樣一來,無論層的位置如何改變,它都會沿著我們創建的曲線行進,而不是默認的線性插值路徑了。這個例子中還有一些細節并未交代的特別清楚,但是這至少已經幫助我們了解如何使用關鍵楨動畫了。

?

    - (void)bounce {
     NSRect rect = [mover frame];
     [[mover animator] setFrameOrigin:rect.origin];
 }
  

?

Recall that since we have added an animation to the animations dictionary under the frameOrigin key, the animator will find it during its search and use ours instead of the default animation.

Animation Types


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 亚洲精品一级一区二区三区 | 国产极品福利视频在线观看 | 久久精品3 | 99国产精品久久久久久久成人热 | 欧美中文在线观看 | 亚洲一级毛片免费看 | 亚洲qingse中文在线 | 国产午夜永久福利视频在线观看 | 欧美性视频在线 | 99久久久久国产 | 麻豆精品在线 | 国产成年人在线观看 | 中文国产日韩欧美视频 | 九九热这里都是精品 | 中文字幕国产在线观看 | 久久精品国产亚洲网站 | 亚洲在线免费视频 | 999国内精品永久免费视频 | 亚洲在线播放 | 天天干天天拍 | 国产成a人片在线观看视频 国产成a人片在线观看视频99 | 中国性猛交xxxx乱大交 | 天天操婷婷 | 亚洲 欧美精品 | 精品国产香蕉 | 国产自产拍精品视频免费看 | aaa级大片| 欧美一区二区三区在线观看 | 五月亭亭免费高清在线 | 欧美日韩国产在线成人网 | 亚洲人成在线精品不卡网 | 国产精品久久久久影院色老大 | 麻豆久久精品 | 玖玖在线精品 | 日本一线一区二区三区免费视频 | 日韩一区二区三区不卡视频 | 日本黄页网 | 人人爱天天做夜夜爽88 | 欧美一级视频在线 | 91不卡在线精品国产 | 国产成人精品一区二区仙踪林 |