日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Facebook POP 使用指南

發(fā)布時(shí)間:2025/3/21 编程问答 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Facebook POP 使用指南 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Facebook POP 使用指南

Pop是一個(gè)動(dòng)畫引擎,用以擴(kuò)展iOS、OSX的動(dòng)畫類型。相較于iOS、OSX中的基本動(dòng)畫效果,Pop擴(kuò)展后支持彈簧動(dòng)畫效果與衰減動(dòng)畫效果,你可以用Pop動(dòng)畫引擎來構(gòu)建出真實(shí)的物理交互效果。它的API與Core Animation的API非常類似,使用起來非常容易。Pop動(dòng)畫引擎已經(jīng)經(jīng)過了良好的測試,我們在 Paper 應(yīng)用中進(jìn)行了大量使用。

安裝

Pop支持 CocoaPods 安裝,將下面一行代碼添加到你的項(xiàng)目中的 Podfile 中:

pod 'pop', '~> 1.0'

注意,bug會(huì)在主分支上面進(jìn)行修復(fù),然后在指定的分支上進(jìn)行發(fā)布。如果你喜歡嘗試最新的不大穩(wěn)定的版本,你可以通過以下入口來訪問主分支:

pod 'pop', :git => 'https://github.com/facebook/pop.git'

使用

Pop 支持Core Animation 中的顯式動(dòng)畫類型,你可以通過導(dǎo)入頭文件來使用它:

#import <pop/POP.h>

開始動(dòng)畫、停止動(dòng)畫與更新動(dòng)畫

開始執(zhí)行一個(gè)動(dòng)畫,你可以將動(dòng)畫添加到一個(gè)對(duì)象中:

POPSpringAnimation *anim = [POPSpringAnimation animation]; ... [layer pop_addAnimation:anim forKey:@"myKey"];

停止一個(gè)動(dòng)畫,你可以根據(jù)一個(gè)鍵值來從對(duì)象中移除掉:

[layer pop_removeAnimationForKey:@"myKey"];

你也可以根據(jù)鍵值來查詢已經(jīng)存在的動(dòng)畫,你可以在執(zhí)行動(dòng)畫效果的同時(shí)來修改toValue屬性來實(shí)時(shí)更新動(dòng)畫效果:

anim = [layer pop_animationForKey:@"myKey"]; if (anim) {/* update to value to new destination */anim.toValue = @(42.0); } else {/* create and start a new animation */.... }

注意,雖然上述示例中用到了一個(gè)layer,但是Pop動(dòng)畫引擎是基于 NSObject 所寫的一個(gè)category,任何繼承自NSObject的對(duì)象都可以使用Pop動(dòng)畫引擎。

動(dòng)畫類型

Pop支持4種動(dòng)畫類型:彈簧效果、衰減效果、基本動(dòng)畫效果與自定義動(dòng)畫效果。

彈簧效果可以用來實(shí)現(xiàn)仿真的物理彈簧特效,在下面的這個(gè)例子中,我們用彈簧效果來對(duì)一個(gè)layer的尺寸進(jìn)行縮放:

效果圖:

源碼:

#import "ViewController.h" #import "POP.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];// 創(chuàng)建layerCALayer *layer = [CALayer layer];layer.frame = CGRectMake(0, 0, 50, 50);layer.backgroundColor = [UIColor cyanColor].CGColor;layer.cornerRadius = 25.f;layer.position = self.view.center;[self.view.layer addSublayer:layer];// 執(zhí)行Spring動(dòng)畫POPSpringAnimation *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerScaleXY];anim.toValue = [NSValue valueWithCGPoint:CGPointMake(3.f, 3.f)];anim.springSpeed = 0.f;[layer pop_addAnimation:anim forKey:@"ScaleXY"]; }@end

衰減效果可以用來模擬真實(shí)的物理減速效果,在下面的例子中,我們用衰減效果來對(duì)一個(gè)view的拖拽停止執(zhí)行減速效果。

效果圖:

源碼:

#import "ViewController.h" #import "POP.h"@interface ViewController ()<POPAnimationDelegate>@property(nonatomic) UIControl *dragView;@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];// 初始化dragViewself.dragView = [[UIControl alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];self.dragView.center = self.view.center;self.dragView.layer.cornerRadius = CGRectGetWidth(self.dragView.bounds)/2;self.dragView.backgroundColor = [UIColor cyanColor];[self.view addSubview:self.dragView];[self.dragView addTarget:selfaction:@selector(touchDown:)forControlEvents:UIControlEventTouchDown];// 添加手勢UIPanGestureRecognizer *recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:selfaction:@selector(handlePan:)];[self.dragView addGestureRecognizer:recognizer]; }- (void)touchDown:(UIControl *)sender {[sender.layer pop_removeAllAnimations]; }- (void)handlePan:(UIPanGestureRecognizer *)recognizer {// 拖拽CGPoint translation = [recognizer translationInView:self.view];recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x,recognizer.view.center.y + translation.y);[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];// 拖拽動(dòng)作結(jié)束if(recognizer.state == UIGestureRecognizerStateEnded){// 計(jì)算出移動(dòng)的速度CGPoint velocity = [recognizer velocityInView:self.view];// 衰退減速動(dòng)畫POPDecayAnimation *positionAnimation = \[POPDecayAnimation animationWithPropertyNamed:kPOPLayerPosition];// 設(shè)置代理positionAnimation.delegate = self;// 設(shè)置速度動(dòng)畫positionAnimation.velocity = [NSValue valueWithCGPoint:velocity];// 添加動(dòng)畫[recognizer.view.layer pop_addAnimation:positionAnimationforKey:@"layerPositionAnimation"];} }@end

基本動(dòng)畫效果可以指定具體的動(dòng)畫時(shí)間,與 CoreAnimation 中的 CABasicAnimation 的用法極為類似,在下面的例子中,我們用基本動(dòng)畫效果來設(shè)置一個(gè)view的alpha值。

效果圖:

源碼:

#import "ViewController.h" #import "POP.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];// 創(chuàng)建viewUIView *showView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];showView.alpha = 0.f;showView.layer.cornerRadius = 50.f;showView.center = self.view.center;showView.backgroundColor = [UIColor cyanColor];[self.view addSubview:showView];// 執(zhí)行基本動(dòng)畫效果POPBasicAnimation *anim = [POPBasicAnimation animationWithPropertyNamed:kPOPViewAlpha];anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];anim.fromValue = @(0.0);anim.toValue = @(1.0);anim.duration = 4.f;[showView pop_addAnimation:anim forKey:@"fade"]; }@end

自定義動(dòng)畫效果是根據(jù) CADisplayLink 來計(jì)算出中間的差值,然后由你來處理輸出的值的動(dòng)畫效果,詳情請參考相關(guān)頭文件來獲取更多的細(xì)節(jié)。

屬性

屬性是通過 POPAnimatableProperty 來定義的。在下面的這個(gè)例子中,我們創(chuàng)建出了一個(gè)彈簧動(dòng)畫效果并顯式的設(shè)置它去響應(yīng) -[CALayer bounds]:

POPSpringAnimation *anim = [POPSpringAnimation animation]; anim.property = [POPAnimatableProperty propertyWithName:kPOPLayerBounds];

Pop動(dòng)畫引擎本身提供了很多可以做動(dòng)畫的屬性供你定制。你可以在這個(gè)類里面創(chuàng)建出一個(gè)實(shí)例對(duì)象:

prop = [POPAnimatableProperty propertyWithName:@"com.foo.radio.volume" initializer:^(POPMutableAnimatableProperty *prop) {// read valueprop.readBlock = ^(id obj, CGFloat values[]) {values[0] = [obj volume];};// write valueprop.writeBlock = ^(id obj, const CGFloat values[]) {[obj setVolume:values[0]];};// dynamics thresholdprop.threshold = 0.01; }];anim.property = prop;

為了了解更多的可以做動(dòng)畫效果的屬性,你可以參考 POPAnimatableProperty.h 查看更多的細(xì)節(jié)。

相關(guān)資源

以下是一些示例供你學(xué)習(xí):

  • AGGeometryKit+POP - Animating Quadrilaterals with Pop
  • Apple – Core Animation Programming Guide
  • Codeplease – Bridging the gesture to animation gap
  • Codeplease – Playing with Pop (iii)
  • Codeplease – Adding a custom animatable property
  • iOS Development Tips – UIScrollView-like deceleration with Pop
  • Pop Playground – Repository of Pop animation examples
  • Pop Playground 2 – Playing with Facebook's framework
  • POP-MCAnimate – Concise syntax for the Pop animation framework
  • Popping - Great examples in one project
  • Rebound – Spring Animations for Android
  • Tapity Tutorial – Getting Started with Pop
  • Tweaks – Easily adjust parameters for iOS apps in development
  • POP Tutorial in 5 steps
  • VBFPopFlatButton – Flat animatable button, using Pop to transition between states

轉(zhuǎn)載于:https://www.cnblogs.com/YouXianMing/p/4398232.html

總結(jié)

以上是生活随笔為你收集整理的Facebook POP 使用指南的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。