使用masonry做动画

比如要实现一个view的出现和隐藏,我用过以下三种方式分别实现过,记录如下:

//1.通过改变frame的y坐标来做动画实现(其中flag是为了控制动画执行完毕后才执行下一次动画)
if (!self.flag && self.commentBar.frame.origin.y == self.view.frame.size.height - 50) {
            [UIView animateWithDuration:0.2 animations:^{
                self.flag = YES;
                CGRect frame = self.commentBar.frame;
                frame.origin.y += 50;
                self.commentBar.frame = frame;
            } completion:^(BOOL finished) {
                self.flag = NO;
            }];
        }
-(void)showInView:(UIView *)View{
    
    YQShareButton *btn =[self viewWithTag:105];
    if (_favoritesId == 0)
    {
        [btn setImage:[UIImage imageNamed:@"ic_collect_empty"] forState:UIControlStateNormal];
        [btn setTitle:@"收藏" forState:UIControlStateNormal];
    }
    else
    {
        [btn setImage:[UIImage imageNamed:@"ic_dia_collect(1)"] forState:UIControlStateNormal];
        [btn setTitle:@"取消收藏" forState:UIControlStateNormal];
    }
    
    [View addSubview:self];
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsZero);
    }];
    //动画之前一定要先调用这个额
    [View layoutIfNeeded];

    [self.shareViewBottomHideConst uninstall];
    [self.shareViewBottomShowConst install];
    [UIView animateWithDuration:0.2 animations:^{
        [View layoutIfNeeded];
    }];
}
[self.shareViewBottomShowConst uninstall];
    [self.shareViewBottomHideConst install];
    [UIView animateWithDuration:0.2 animations:^{
        [self layoutIfNeeded];
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];

你可能感兴趣的:(使用masonry做动画)