Facebook開源動畫庫 POP-小執行個體,facebookpop-

來源:互聯網
上載者:User

Facebook開源動畫庫 POP-小執行個體,facebookpop-

執行個體1:圖片視圖跟著手在螢幕上的點改變大小

- (void)viewDidLoad{    [super viewDidLoad];    //添加手勢    UIPanGestureRecognizer *gesture = [[UIPanGestureRecognizer alloc] init];    [gesture addTarget:self action:@selector(changeSize:)];    [self.view addGestureRecognizer:gesture];    }- (void)changeSize:(UIPanGestureRecognizer*)tap{    POPSpringAnimation *springAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewFrame];    CGPoint point = [tap locationInView:self.view];    springAnimation.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, point.x, point.y)];    //彈性值    springAnimation.springBounciness = 20.0;    //彈性速度    springAnimation.springSpeed = 20.0;    [_springView pop_addAnimation:springAnimation forKey:@"changeframe"];}

執行個體2:實現一個彈出收縮視圖的效果,彈出來有彈性的效果,收縮有變小的效果

- (void)viewDidLoad{    [super viewDidLoad];        _showPosition = CGRectMake(320-147, 5, 147, 160);    _hidePosition = CGRectMake(320, 5, 0, 0);        _popView = [[UIImageView alloc] initWithFrame:_hidePosition];    _popView.image = [UIImage imageNamed:@"menu.png"];    [self.view addSubview:_popView];    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"+" style:UIBarButtonItemStyleDone target:self action:@selector(showPop)];        //讓螢幕從導覽列下開始算(0,0)    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {        self.edgesForExtendedLayout = UIRectEdgeNone;    }}- (void)showPop{        if (_isOpened) {        [self hidePop];        return;    }    _isOpened = YES;        POPSpringAnimation *positionAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewFrame];    positionAnimation.fromValue = [NSValue valueWithCGRect:_hidePosition];    positionAnimation.toValue = [NSValue valueWithCGRect:_showPosition];    positionAnimation.springBounciness = 15.0f;    positionAnimation.springSpeed = 20.0f;    [_popView pop_addAnimation:positionAnimation forKey:@"frameAnimation"];}- (void)hidePop{        POPBasicAnimation *positionAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPViewFrame];    positionAnimation.fromValue = [NSValue valueWithCGRect:_showPosition];    positionAnimation.toValue = [NSValue valueWithCGRect:_hidePosition];    [_popView pop_addAnimation:positionAnimation forKey:@"frameAnimation"];     _isOpened = NO;}

執行個體3:建立兩個按鍵,增加兩個動畫效果,其中一個按鍵是動畫改變大小,另外一個修改ViewFrame,只要定位好座標跟大小可以做出很不錯的動畫

@interface ViewController ()@property (nonatomic, retain) UIView *button;@property (nonatomic, retain) UIView *popOut;@property (readwrite, assign) BOOL timerRunning;@end@implementation ViewController- (void)viewDidLoad{    [super viewDidLoad];        _popOut = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TimerPopOut"]];    [_popOut setFrame:CGRectMake(245, 70, 0, 0)];    [self.view addSubview:_popOut];        _button = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TimerButton"]];    [_button setFrame:CGRectMake(240, 50, 46, 46)];    [self.view addSubview:_button];        _timerRunning = NO;        [self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(demoAnimate:)]];}- (void)demoAnimate:(UITapGestureRecognizer*)tap{    _timerRunning = !_timerRunning;        POPSpringAnimation *buttonAnimation = [POPSpringAnimation animation];    buttonAnimation.property = [POPAnimatableProperty propertyWithName:kPOPLayerSize];    if (_timerRunning) {        buttonAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(37, 37)];    }    else {        buttonAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(46, 46)];    }    buttonAnimation.springBounciness = 10.0;    buttonAnimation.springSpeed = 10.0;    [_button pop_addAnimation:buttonAnimation forKey:@"pop"];            POPSpringAnimation *popOutAnimation = [POPSpringAnimation animation];    popOutAnimation.property = [POPAnimatableProperty propertyWithName:kPOPViewFrame];    if (!_timerRunning) {        popOutAnimation.toValue = [NSValue valueWithCGRect:CGRectMake(245, 70, 0, 10)];    }    else {        popOutAnimation.toValue = [NSValue valueWithCGRect:CGRectMake(180, 60, 75, 26)];    }    popOutAnimation.velocity = [NSValue valueWithCGRect:CGRectMake(200, 0, 300, -200)];    popOutAnimation.springBounciness = 10.0;    popOutAnimation.springSpeed = 10.0;    [_popOut pop_addAnimation:popOutAnimation forKey:@"slide"];}

 

相關文章

聯繫我們

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