美文网首页
iOS 实现悬浮按钮上下移动

iOS 实现悬浮按钮上下移动

作者: JohnayXiao | 来源:发表于2018-08-09 09:48 被阅读521次

    当scrollView向下滚动时,按钮会向下移动消失,等scrollview向上滚动时,按钮则又会出现。

    Simulator Screen Shot - iPhone X - 2018-08-09 at 09.45.03.png
    //实现scrollView代理
    - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{
        //竖直滑动时 判断是上滑还是下滑
        
    //    NSLog(@"----------%g", velocity.y);
        
        if(velocity.y > 0){
            //上滑
    //        NSLog(@"上滑");
            [UIView animateWithDuration:0.25 animations:^{
                
                CGRect frame = self.topicBtn.frame;
                frame.origin.y = XJ_ScreenHeight;
                self.topicBtn.frame  = frame;
            }];
        }else if (velocity.y < -1){
            //下滑
    //        NSLog(@"下滑");
            [UIView animateWithDuration:0.25 animations:^{
                
                CGRect frame = self.topicBtn.frame;
                frame.origin.y = XJ_ScreenHeight - XJ_TabbarHeight - 35 - frame.size.height;
                self.topicBtn.frame  = frame;
            }];
    
        }
    //    
    //    //水平滑动时 判断是右滑还是左滑
    //    if(velocity.x>0){
    //        //右滑
    //        NSLog(@"右滑");
    //    }else{
    //        //左滑
    //        NSLog(@"左滑");
    //    }
    }
    //点击屏幕顶部触发的方法
    - (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView {
        
        [UIView animateWithDuration:0.25 animations:^{
            
            CGRect frame = self.topicBtn.frame;
            frame.origin.y = XJ_ScreenHeight - XJ_TabbarHeight - 35 - frame.size.height;
            self.topicBtn.frame  = frame;
        }];
    
    }
    

    相关文章

      网友评论

          本文标题:iOS 实现悬浮按钮上下移动

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