美文网首页
悬浮滚动隐藏按钮

悬浮滚动隐藏按钮

作者: ___1o_8o | 来源:发表于2018-03-06 12:27 被阅读82次
    //发帖按钮
    @property (nonatomic, strong) UIButton *postButton;
    
    - (void)prepareHomePostButton {
        [self.view addSubview:self.postButton];
        [self.postButton setFrame:CGRectMake(self.view.width - 50 - 15, self.view.height - 50 - 30 - [BMUtils tabbarBarHeight], 50, 50)];
    }
    
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {   
        if (scrollView.dragging) {
            //手势触发的滚动则隐藏发帖按钮
            [self postButtonAnimationWithHidden:YES];
        }  
    }
    
    - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
        [self postButtonAnimationWithHidden:NO];
    }
    
    - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
        [self postButtonAnimationWithHidden:NO];
    }
    
    - (void)postButtonAnimationWithHidden:(BOOL)hidden {
        self.stopScrollTime = [[NSDate date] timeIntervalSince1970];
        BMWeakSelf
        if (!hidden) {
            CGFloat time = 0.7;
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(time * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                NSTimeInterval nowTime = [[NSDate date] timeIntervalSince1970];
                if (nowTime - weakSelf.stopScrollTime >= time) {
                    [UIView animateWithDuration:0.3 animations:^{
                        weakSelf.postButton.alpha = 1.0;
                    }];
                }
            });
        }
        else {
            if (self.postButton.alpha < 0.01) {
                return;
            }
            [UIView animateWithDuration:0.3 animations:^{
                weakSelf.postButton.alpha = 0.0;
            }];
        }
    }
    

    相关文章

      网友评论

          本文标题:悬浮滚动隐藏按钮

          本文链接:https://www.haomeiwen.com/subject/zhdlfftx.html