flutter开发实战-手势Gesture与ListView滚动竞技场的可滑动关闭组件

flutter开发实战-手势Gesture与ListView滚动竞技场的可滑动关闭组件

最近看到了一个插件,实现一个可滑动关闭组件。滑动关闭组件即手指向下滑动,组件随手指移动,当移动一定位置时候,手指抬起后组件滑出屏幕。

一、GestureDetector嵌套Container非ListView

如果要可滑动关闭,则需要手势GestureDetector,GestureDetector这里实现了onVerticalDragDown、onVerticalDragUpdate、onVerticalDragEnd,通过手势,更新AnimatedContainer的高度。

@override
  Widget build(BuildContext context) {
    Size screenSize = MediaQuery.of(context).size;
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: <Widget>[
        GestureDetector(
          onVerticalDragDown: _onVerticalDragDown,
          onVerticalDragUpdate: _onVerticalDragUpdate,
          onVerticalDragEnd: _onVerticalDragEnd,
          child: AnimatedContainer(
            curve: Curves.easeOut,
            duration: Duration(milliseconds: 250),
            onEnd: () {
              _onAniPositionedEnd(context);
            },
            height: yBottomOffset + widget.displayHeight,
            width: screenSize.width,
            clipBehavior: Clip.hardEdge,
            decoration: const BoxDecoration(
              color: Colors.transparent,
            ),
            child: widget.child,
          ),
        ),
      ],
    );
  }
    

我们通过onVerticalDragUpdate来更新AnimatedContainer的高度height,

void _onVerticalDragUpdate(DragUpdateDetails details) {
    print("_onVerticalDragUpdate");
    if (details.delta.dy <= 0) {
      // 向上
      isDragDirectionUp = true;
    } else {
      // 向下
      isDragDirectionUp = false;
    }
    yBottomOffset -= details.delta.dy;
    if (yBottomOffset > 0.0) {
      yBottomOffset = 0.0;
    }

    if (yBottomOffset < -widget.displayHeight) {
      yBottomOffset = -widget.displayHeight;
    }
    setState(() {});
  }
    

当拖动手势结束之后,来检测是否是隐藏状态。

void _onVerticalDragEnd(DragEndDetails details) {
    print("_onVerticalDragEnd");
    if (yBottomOffset < -widget.displayHeight / 3) {
      // 隐藏移除
      yBottomOffset = -widget.displayHeight;
      isCompleteHide = true;
    } else {
      yBottomOffset = 0.0;
      isCompleteHide = false;
    }
    setState(() {

    });
  }
    

AnimatedContainer中有onEnd方法回调,当动画结束之后,在此方法回调中来处理是否pop等操作

void _onAniPositionedEnd(BuildContext context) {
    print("_onAniPositionedEnd");
    if (isCompleteHide) {
      // 隐藏了,则移除
      Navigator.of(context).pop();
    }
  }
    

DragBottomSheet2完整代码如下

import 'package:flutter/material.dart';

class DragBottomSheet2 extends StatefulWidget {
  const DragBottomSheet2({
    super.key,
    required this.child,
    required this.displayHeight,
  });

  // child
  final Widget child;

  // 展示的child高度
  final double displayHeight;

  @override
  State<DragBottomSheet2> createState() => _DragBottomSheet2State();
}

class _DragBottomSheet2State extends State<DragBottomSheet2> {
  bool? isDragDirectionUp;
  double yBottomOffset = 0.0;
  bool isCompleteHide = false;

  void _onVerticalDragDown(DragDownDetails details) {
    print("_onVerticalDragDown");
  }

  void _onVerticalDragUpdate(DragUpdateDetails details) {
    print("_onVerticalDragUpdate");
    if (details.delta.dy <= 0) {
      // 向上
      isDragDirectionUp = true;
    } else {
      // 向下
      isDragDirectionUp = false;
    }
    yBottomOffset -= details.delta.dy;
    if (yBottomOffset > 0.0) {
      yBottomOffset = 0.0;
    }

    if (yBottomOffset < -widget.displayHeight) {
      yBottomOffset = -widget.displayHeight;
    }
    setState(() {});
  }

  void _onVerticalDragEnd(DragEndDetails details) {
    print("_onVerticalDragEnd");
    if (yBottomOffset < -widget.displayHeight / 3) {
      // 隐藏移除
      yBottomOffset = -widget.displayHeight;
      isCompleteHide = true;
    } else {
      yBottomOffset = 0.0;
      isCompleteHide = false;
    }
    setState(() {});
  }

  void _onAniPositionedEnd(BuildContext context) {
    print("_onAniPositionedEnd");
    if (isCompleteHide) {
      // 隐藏了,则移除
      Navigator.of(context).pop();
    }
  }

  @override
  Widget build(BuildContext context) {
    Size screenSize = MediaQuery.of(context).size;
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: <Widget>[
        GestureDetector(
          onVerticalDragDown: _onVerticalDragDown,
          onVerticalDragUpdate: _onVerticalDragUpdate,
          onVerticalDragEnd: _onVerticalDragEnd,
          child: AnimatedContainer(
            curve: Curves.easeOut,
            duration: Duration(milliseconds: 250),
            onEnd: () {
              _onAniPositionedEnd(context);
            },
            height: yBottomOffset + widget.displayHeight,
            width: screenSize.width,
            clipBehavior: Clip.hardEdge,
            decoration: const BoxDecoration(
              color: Colors.transparent,
            ),
            child: widget.child,
          ),
        ),
      ],
    );
  }
}

    

点击按钮弹出bottomSheet2代码如下

void showBottomSheet2(BuildContext context) {
    Size size = MediaQuery.of(context).size;
    double displayHeight = size.height - 88;
    showModalBottomSheet(
      context: context,
      isScrollControlled: true,
      builder: (ctx) {
        return DragBottomSheet2(
          displayHeight: displayHeight,
          child: Container(
            width: size.width,
            height: displayHeight,
            color: Colors.orangeAccent,
            child: Text(
              '内容',
              style: TextStyle(
                color: Colors.black,
              ),
            ),
          ),
        );
      },
    );
  }
    

效果图如下

在这里插入图片描述

二、GestureDetector嵌套ListView

GestureDetector嵌套ListView后,Flutter会根据竞技场Arena机制,通过一定逻辑选择一个组件胜出。
Flutter为了解决手势冲突问题,Flutter给开发者提供了一套解决方案。在该方案中,Flutter引入了Arena(竞技场)概念,然后把冲突的手势加入到Arena中并竞争,谁胜利,谁就获得手势的后续处理权。

Arena竞技场的原理请看https://juejin.cn/post/6874570159768633357

所以在GestureDetector嵌套ListView后,Flutter框架会将这些Gesture与ListView组件都加入竞技场,然后通过一定的逻辑选择一个组件胜出,通常同类组件嵌套时最内层的组件胜出,胜出的组件会处理接下来的move和up事件,其它组件则不会继续处理这些事件了。所以在GestureDetector嵌套ListView的场景中,由于是ListView最终胜出,所以后续的事件都交由ListView处理,而GestureDetector收不到后续的事件,也就不会响应用户的手势了。因此,我们解决这个问题的第一步就是要让GestureDetector在这种场景下也能收到后续的事件

参考请看https://zhuanlan.zhihu.com/p/680586251

我们需要根据GestureDetector真正处理用户手势事件的是内部的Recognizer,比如处理上下滑动的是VerticalDragGestureRecognizer而Recognizer在竞技场失败后也可以单方面宣布自己胜出这样即使在竞技场失败了,GestureDetector也能收到后续的手势事件
因此我们现定义一个单方面宣布胜出的Recognizer

class _MyVerticalDragGestureRecognizer extends VerticalDragGestureRecognizer {
  @override
  void rejectGesture(int pointer) {
    // 单方面宣布自己胜出
    acceptGesture(pointer);
  }
}
    

我们需要将Recognizer加入到GestureDetector中,会用到RawGestureDetector

RawGestureDetector(
      gestures: {
        _MyVerticalDragGestureRecognizer: GestureRecognizerFactoryWithHandlers<
                _MyVerticalDragGestureRecognizer>(
            () => _MyVerticalDragGestureRecognizer(),
            (_MyVerticalDragGestureRecognizer recognizer) {
          recognizer
            ..onStart = (DragStartDetails details) {
              
            }
            ..onUpdate = (DragUpdateDetails details) {
              
            }
            ..onEnd = (DragEndDetails details) {
             
            };
        }),
      },
      child: ...
    );
    

这时候当滚动ListView时候,也能收到手势事件了。

监听ListView的滚动,时候我们需要用到NotificationListener

 NotificationListener(  // 监听内部ListView的滑动变化
              onNotification: (ScrollNotification notification) {
                if (notification is OverscrollNotification && notification.overscroll < 0) {
                  // 用户向下滑动,ListView已经滑动到顶部,处理GestureDetector的滑动事件
                } else if (notification is ScrollUpdateNotification) {
                  // 用户在ListView中执行滑动动作,关闭外部GestureDetector的滑动处理
                } else {
                  
                }

                return false;
              },
              child:  //ListView
            ),
    

最后DragGestureBottomSheet完整代码如下

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app_demolab/drag_sheet_controller.dart';

class DragGestureBottomSheet extends StatefulWidget {
  const DragGestureBottomSheet({
    super.key,
    required this.child,
    required this.displayHeight,
    this.duration = const Duration(milliseconds: 200),
    this.openDraggable = true,
    this.autoNavigatorPop = true,
    this.onShow,
    this.onHide,
  });

  // child
  final Widget child;

  // 展示的child高度
  final double displayHeight;

  // 拖动动画时长duration
  final Duration duration;

  // 是否需要拖动
  final bool openDraggable;

  // 是否需要自动pop
  final bool autoNavigatorPop;

  // This method will be executed when the solid bottom sheet is completely
  // opened.
  final void Function()? onShow;

  // This method will be executed when the solid bottom sheet is completely
  // closed.
  final void Function()? onHide;

  @override
  State<DragGestureBottomSheet> createState() => _DragGestureBottomSheetState();
}

class _DragGestureBottomSheetState extends State<DragGestureBottomSheet> {
  bool? isDragDirectionUp;
  double yBottomOffset = 0.0;
  bool isDraggable = false;
  bool isCompleteHide = false;

  DragSheetController? dragSheetController;

  @override
  void initState() {
    // TODO: implement initState
    dragSheetController = DragSheetController();
    dragSheetController?.dispatch(widget.displayHeight);
    super.initState();
  }

  @override
  void dispose() {
    // TODO: implement dispose
    dragSheetController?.dispose();
    super.dispose();
  }

  void _onVerticalDragUpdate(data) {
    if (widget.openDraggable) {
      print("data.delta.dy:${data.delta.dy}");
      if (data.delta.dy <= 0) {
        // 向上
        isDragDirectionUp = true;
      } else {
        // 向下
        isDragDirectionUp = false;
      }
      yBottomOffset -= data.delta.dy;
      if (yBottomOffset > 0.0) {
        yBottomOffset = 0.0;
      }

      if (yBottomOffset < -widget.displayHeight) {
        yBottomOffset = -widget.displayHeight;
      }

      double height = widget.displayHeight + yBottomOffset;
      dragSheetController?.dispatch(height);
    }

  }

  void _onVerticalDragEnd(data) {
    if (widget.openDraggable) {
      // 根据判断是否隐藏与显示
      if (false == isDragDirectionUp) {
        if (yBottomOffset < -widget.displayHeight / 3) {
          // 隐藏移除
          yBottomOffset = -widget.displayHeight;
          isCompleteHide = true;
        } else {
          yBottomOffset = 0.0;
          isCompleteHide = false;
        }
      } else {
        yBottomOffset = 0.0;
        isCompleteHide = false;
      }

      double height = widget.displayHeight + yBottomOffset;
      dragSheetController?.dispatch(height);
    }
  }

  void _onAniPositionedEnd(BuildContext context) {
    // 动画结束
    print("_onAniPositionedEnd");
    if (isCompleteHide) {
      // 隐藏,则调用hiden
      if (widget.onHide != null) {
        widget.onHide!.call();
      }
    } else {
      // 显示,则调用show
      if (widget.onShow != null) {
        widget.onShow!.call();
      }
    }

    if (isCompleteHide && widget.autoNavigatorPop) {
      // 隐藏了,则移除
      Navigator.of(context).pop();
    }
  }

  @override
  Widget build(BuildContext context) {
    Size screenSize = MediaQuery.of(context).size;
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: <Widget>[
        RawGestureDetector(
          gestures: {
            _MyVerticalDragGestureRecognizer:
                GestureRecognizerFactoryWithHandlers<
                        _MyVerticalDragGestureRecognizer>(
                    () => _MyVerticalDragGestureRecognizer(),
                    (_MyVerticalDragGestureRecognizer recognizer) {
              recognizer
                ..onStart = (DragStartDetails details) {}
                ..onUpdate = (DragUpdateDetails details) {
                  if (!isDraggable) {
                    return;
                  }
                  _onVerticalDragUpdate(details);
                }
                ..onEnd = (DragEndDetails details) {
                  _onVerticalDragEnd(details);
                };
            }),
          },
          child: StreamBuilder(
            stream: dragSheetController?.streamData,
            initialData: widget.displayHeight,
            builder: (_, snapshot) {
              return AnimatedContainer(
                curve: Curves.easeOut,
                duration: widget.duration,
                onEnd: () {
                  _onAniPositionedEnd(context);
                },
                height: snapshot.data,
                width: screenSize.width,
                clipBehavior: Clip.hardEdge,
                decoration: const BoxDecoration(
                  color: Colors.transparent,
                ),
                child: NotificationListener(
                  // 监听内部ListView的滑动变化
                  onNotification: (ScrollNotification notification) {
                    if (notification is OverscrollNotification &&
                        notification.overscroll < 0) {
                      // 用户向下滑动,ListView已经滑动到顶部,处理GestureDetector的滑动事件
                      isDraggable = true;
                    } else if (notification is ScrollUpdateNotification) {
                      // 用户在ListView中执行滑动动作,关闭外部GestureDetector的滑动处理
                      isDraggable = false;
                    } else {}

                    return false;
                  },
                  child: widget.child,
                ),
              );
            },
          ),
        )
      ],
    );
  }
}

class _MyVerticalDragGestureRecognizer extends VerticalDragGestureRecognizer {
  @override
  void rejectGesture(int pointer) {
    // 单方面宣布自己胜出
    acceptGesture(pointer);
  }
}

三、DragSheetController处理数据流

这里定义了DragSheetController来处理数据流,DragSheetController中包括streamController、subscription、streamSink、streamData

StreamBuilder是一个Widget,它依赖Stream来做异步数据获取刷新widget。
Stream是一种用于异步处理数据流的机制,它允许我们从一端发射一个事件,从另外一端去监听事件的变化.Stream类似于JavaScript中的Promise、Swift中的Future或Java中的RxJava,它们都是用来处理异步事件和数据的。Stream是一个抽象接口,我们可以通过StreamController接口可以方便使用Stream。

使用详情请查看https://brucegwo.blog.csdn.net/article/details/136232000

最后DragSheetController代码如下

import 'dart:async';

/// 处理Stream、StreamController相关逻辑
class DragSheetController  {
  StreamSubscription<double>? subscription;

  //创建StreamController
  StreamController<double>? streamController = StreamController<double>.broadcast();

  // 获取StreamSink用于发射事件
  StreamSink<double>? get streamSink => streamController?.sink;

  // 获取Stream用于监听
  Stream<double>? get streamData => streamController?.stream;

  // Adds new values to streams
  void dispatch(double value) {
    streamSink?.add(value);
  }

  // Closes streams
  void dispose() {
    streamSink?.close();
  }
}
    

通过DragSheetController,当拖动时候高度发生变化时候会调用dispatch方法,dispatch来发射数据流,DragGestureBottomSheet中通过StreamBuilder来调整AnimatedContainer的高度。

最后调用使用DragGestureBottomSheet

我们使用showModalBottomSheet展示DragGestureBottomSheet时候

// 显示底部弹窗
  void showCustomBottomSheet(BuildContext context) {
    Size size = MediaQuery.of(context).size;
    double displayHeight = size.height - 88;
    showModalBottomSheet(
      context: context,
      isScrollControlled: true,
      builder: (ctx) {
        return DragGestureBottomSheet(
          displayHeight: displayHeight,
          autoNavigatorPop: true,
          openDraggable: true,
          onHide: () {
            print("onHide");
          },
          onShow: () {
            print("onShow");
          },
          child: Container(
            width: size.width,
            height: displayHeight,
            color: Colors.white,
            child: ScrollConfiguration(
              behavior: NoIndicatorScrollBehavior(),
              child: ListView.builder(
                itemCount: 20,
                physics: ClampingScrollPhysics(),
                itemBuilder: (context, index) {
                  return GestureDetector(
                    child: Container(
                      width: size.width,
                      height: 100,
                      decoration: BoxDecoration(
                        color: Colors.transparent,
                        border: Border.all(
                          color: Colors.black12,
                          width: 0.25,
                          style: BorderStyle.solid,
                        ),
                      ),
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Text('index -- $index'),
                          SizedBox(
                            width: 50,
                            child: ClipOval(
                                child:
                                    Image.asset("assets/images/hero_test.png")),
                          ),
                        ],
                      ),
                    ),
                    onTap: () {
                      Navigator.of(context).push(
                          CupertinoPageRoute(builder: (BuildContext context) {
                        return HeroPage();
                      }));
                    },
                  );
                },
              ),
            ),
          ),
        );
      },
    );
  }
    

效果图如下

在这里插入图片描述

https://brucegwo.blog.csdn.net/article/details/136241765

四、小结

flutter开发实战-手势Gesture与ListView滚动竞技场的可滑动关闭组件

学习记录,每天不停进步。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/410430.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

配置多个后端 API 代理

在开发 React 应用时&#xff0c;通常会涉及到与后端 API 的交互。而在开发过程中&#xff0c;我们经常需要在开发环境中使用代理来解决跨域请求的问题。Create React App 提供了一种简单的方式来配置代理&#xff0c;即通过创建一个名为 setupProxy.js 的文件来配置代理规则。…

力扣链表篇

以下刷题思路来自代码随想录以及官方题解 文章目录 203.移除链表元素707.设计链表206.反转链表24.两两交换链表中的节点19.删除链表的倒数第N个节点面试题 02.07. 链表相交142.环形链表II 203.移除链表元素 给你一个链表的头节点 head 和一个整数 val &#xff0c;请你删除链…

一个具有强大PDF处理能力的.Net开源项目

PDF具有跨平台、可读性强、不可修改性、无需特定阅读软件、内容安全等好处&#xff0c;在工作中经常都会用到。 所以&#xff0c;我们在项目开发中&#xff0c;经常需要生成PDF的文件&#xff0c;或者把Html、Xml等文件转化为PDF格式。 今天给大家推荐一个具有PDF处理能力的.…

计算机设计大赛 深度学习大数据物流平台 python

文章目录 0 前言1 课题背景2 物流大数据平台的架构与设计3 智能车货匹配推荐算法的实现**1\. 问题陈述****2\. 算法模型**3\. 模型构建总览 **4 司机标签体系的搭建及算法****1\. 冷启动**2\. LSTM多标签模型算法 5 货运价格预测6 总结7 部分核心代码8 最后 0 前言 &#x1f5…

vue - - - - Vue3+i18n多语言动态国际化设置

Vue3i18n多语言动态国际化设置 前言一、 i18n 介绍二、插件安装三、i18n配置3.1 创建i18n对应文件夹/文件3.2 en-US.js3.3 zh-CN.js3.4 index.js 四、 mian.js 引入 i18n配置文件五、 组件内使用六、使用效果 前言 继续【如何给自己的网站添加中英文切换】一文之后&#xff0c…

Folx Pro Mac中文p破解版如何使用?为您带来Folx Pro 详细使用教程!

​ Folx pro 5 中文版是mac上一款功能强大的老牌加速下载软件&#xff0c;新版本的Folx pro整体界面非常的简洁和漂亮&#xff0c;具有非常好用的分类管理功能&#xff0c;支持高速下载、定时下载、速度控制、iTunes集成等功能。Folx pro兼容主流的浏览器&#xff0c;不但可以下…

AI对话系统app开源

支持对接gpt&#xff0c;阿里云&#xff0c;腾讯云 具体看截图 后端环境&#xff1a;PHP7.4MySQL5.6 软件&#xff1a;uniapp 废话不多说直接上抗揍云链接&#xff1a; https://mny.lanzout.com/iKFRY1o1zusf 部署教程请看源码内的【使用教程】文档 欢迎各位转载该帖/源码

【postgresql】数据表id自增与python sqlachemy结合实例

需求&#xff1a; postgresql实现一个建表语句&#xff0c;表名&#xff1a;student,字段id,name,age&#xff0c; 要求&#xff1a;每次添加一个数据id会自动增加1 在PostgreSQL中&#xff0c;您可以使用SERIAL或BIGSERIAL数据类型来自动生成主键ID。以下是一个创建名为stude…

Jmeter系列(1)Mac下载安装启动

目录 Jmeter下载安装启动下载启动 Jmeter下载安装启动 注意⚠️&#xff1a;使用jmeter需要有java环境 下载 官网下载地址&#xff1a;https://jmeter.apache.org/ 会看到这里有两个版本&#xff0c;那么有什么区别么&#xff1f; Binaries是可执行版&#xff0c;直接下载解…

韩国量子之梦:将量子计算纳入新增长 4.0战略

内容来源&#xff1a;量子前哨&#xff08;ID&#xff1a;Qforepost&#xff09; 编辑丨王珩 编译/排版丨沛贤 深度好文&#xff1a;1500字丨9分钟阅读 据《朝鲜邮报》报道&#xff0c;韩国将推出由量子计算加速的云服务&#xff0c;并在首尔地区启动城市空中交通的试飞&…

企业过二级等保采购哪家堡垒机好?

企业常见过等保&#xff0c;一般是指等保二级或者三级。这不2024开年&#xff0c;不少企业在问&#xff0c;过二级等保采购哪家堡垒机好&#xff1f;电话多少&#xff1f;这里我们小编就给大家毛遂自荐一下吧&#xff01; 企业过二级等保采购哪家堡垒机好&#xff1f; 【回答】…

Spring Boot Profiles简单介绍

Spring Boot application.properties和application.yml文件的配置 阅读本文之前&#xff0c;请先阅读上面的配置文件介绍。 Spring Boot Profiles是一个用于区分不同环境下配置的强大功能。以下是如何在Spring Boot应用程序中使用Profiles的详细步骤和代码示例。 1. 创…

一周学会Django5 Python Web开发-Django5命名空间namespace

锋哥原创的Python Web开发 Django5视频教程&#xff1a; 2024版 Django5 Python web开发 视频教程(无废话版) 玩命更新中~_哔哩哔哩_bilibili2024版 Django5 Python web开发 视频教程(无废话版) 玩命更新中~共计25条视频&#xff0c;包括&#xff1a;2024版 Django5 Python we…

2024年2月20日v1.0.5更新·优雅草便民工具youyacao-tools

2024年2月20日v1.0.5更新优雅草便民工具youyacao-tools apk下载 https://fenfacun.youyacao.com/tools105.apk 介绍 优雅草便民工具是一款由成都市一颗优雅草科技有限公司打造的便民查询公益工具&#xff0c;2024年1月17日正式发布v1.0.0版本&#xff0c;本工具为了方便大众免…

Linux-部署各类软件(黑马学习笔记)

MYSQL MYSQL5.7版本在CentOS系统安装 注意&#xff1a;安装操作需要root权限 MySQL的安装我们可以通过前面学习的yum命令进行。 安装 1.配置yum仓库 # 更新密钥 rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022# 安装Mysql yum库 rpm -Uvh http://repo.mysql.…

运维管理制度优化:确保IT系统稳定运行的关键策略

1、总则 第一条&#xff1a;为保障公司信息系统软硬件设备的良好运行&#xff0c;使员工的运维工作制度化、流程化、规范化&#xff0c;特制订本制度。 第二条&#xff1a;运维工作总体目标&#xff1a;立足根本促发展&#xff0c;开拓运维新局面。在企业发展壮大时期&#x…

pytorch保存张量为图片

这里用到的是torchvision中的save_image。 废话不多说&#xff0c;直接来代码&#xff1a; import torch from torchvision.utils import save_image B, C, H, W 64, 3, 32, 32 input_tensor torch.randn(B, C, H, W) save_image(input_tensor, "hh.png", nrow8)…

力扣随笔删除有序数组中的重复项(简单26)

思路&#xff1a;根据类似于滑动窗口的思想&#xff0c;定义一个指针&#xff1b;使指针左边的区域全部为不重复元素&#xff08;包括指针所指的数字&#xff09; 以示例2为例&#xff0c;left&#xff1a;红色加粗 遍历指针i&#xff1a;黑色加粗 窗口范围&#xff0c;左边界到…

庖丁解牛-二叉树的遍历

庖丁解牛-二叉树的遍历 〇、前言 01 文章内容 一般提到二叉树的遍历&#xff0c;我们是在说 前序遍历、中序遍历、后序遍历和层序遍历 或者说三序遍历层序遍历&#xff0c;毕竟三序和层序的遍历逻辑相差比较大下面讨论三序遍历的递归方法、非递归方法和非递归迭代的统一方法然…

调度服务看门狗配置

查看当前服务器相关的sqlserver服务 在任务栏右键&#xff0c;选择点击启动任务管理器 依次点击&#xff0c;打开服务 找到sqlserver 相关的服务&#xff0c; 确认这些服务是启动状态 将相关服务在看门狗中进行配置 选择调度服务&#xff0c;双击打开 根据上面找的服务进行勾…