iOS开发-CAShapeLayer与UIBezierPath实现微信首页的下拉菜单效果

news/2024/5/16 11:39:23/文章来源:https://blog.csdn.net/gloryFlow/article/details/131993997

iOS开发-CAShapeLayer与UIBezierPath实现微信首页的下拉菜单效果

之前开发中遇到需要使用实现微信首页的下拉菜单效果。用到了CAShapeLayer与UIBezierPath绘制菜单外框。

在这里插入图片描述

一、效果图

在这里插入图片描述

二、CAShapeLayer与UIBezierPath

2.1、CAShapeLayer是什么?

CAShapeLayer继承自CALayer,可使用CALayer的所有属性
CAShapeLayer需要和UIBezierPath绘制图形。

创建shapeLayer

// 创建 shapeLayer
CAShapeLayer *shapeLayer = [[CAShapeLayer alloc]init];
[self.view.layer addSublayer:shapeLayer];
shapeLayer.path = path.CGPath;
shapeLayer.fillColor = [UIColor clearColor].CGColor;
shapeLayer.strokeColor = [UIColor blackColor].CGColor;
shapeLayer.lineWidth = 5;

2.2、UIBezierPath是什么?

UIBezierPath即贝塞尔曲线
UIBezierPath 类允许你在自定义的 View 中绘制和渲染由直线和曲线组成的路径

+ (instancetype)bezierPath;
+ (instancetype)bezierPathWithRect:(CGRect)rect;
+ (instancetype)bezierPathWithOvalInRect:(CGRect)rect;
+ (instancetype)bezierPathWithRoundedRect:(CGRect)rect cornerRadius:(CGFloat)cornerRadius; // rounds all corners with the same horizontal and vertical radius
+ (instancetype)bezierPathWithRoundedRect:(CGRect)rect byRoundingCorners:(UIRectCorner)corners cornerRadii:(CGSize)cornerRadii;
+ (instancetype)bezierPathWithArcCenter:(CGPoint)center radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(BOOL)clockwise;
+ (instancetype)bezierPathWithCGPath:(CGPathRef)CGPath;

三、绘制箭头

在弹出的菜单弹出时候会显示箭头,这里使用UIBezierPath和CAShapeLayer绘制箭头。

#pragma mark - DrawShapeLayer
- (void)drawShapeLayer {CGFloat startPointX = self.contentStartPoint.x;CGFloat startPointY = self.contentStartPoint.y;CGFloat width = CGRectGetWidth(self.contentBGImageView.frame);CGFloat height = CGRectGetHeight(self.contentBGImageView.frame);self.path = [UIBezierPath bezierPath]; // 创建路径[self.path moveToPoint:CGPointMake(startPointX, startPointY)]; // 设置起始点[self.path addLineToPoint:CGPointMake(startPointX + 5.0, kAnchorHeight)];[self.path addLineToPoint:CGPointMake(width - 5.0, kAnchorHeight)];[self.path addArcWithCenter:CGPointMake(width - 5.0, kAnchorHeight + 5.0) radius:5 startAngle:KCP*3/2 endAngle:2*KCP clockwise:YES]; // 绘制一个圆弧[self.path addLineToPoint:CGPointMake(width, height - 5.0)];[self.path addArcWithCenter:CGPointMake(width - 5.0, height - 5.0) radius:5 startAngle:0 endAngle:KCP/2 clockwise:YES]; // 绘制一个圆弧[self.path addLineToPoint:CGPointMake(5, height)];[self.path addArcWithCenter:CGPointMake(5.0, height-5.0) radius:5 startAngle:KCP/2 endAngle:KCP clockwise:YES]; // 绘制一个圆弧[self.path addLineToPoint:CGPointMake(0.0, kAnchorHeight + 5.0)];[self.path addArcWithCenter:CGPointMake(5, kAnchorHeight + 5) radius:5 startAngle:KCP endAngle:KCP*3/2 clockwise:YES]; // 绘制一个圆弧[self.path addLineToPoint:CGPointMake(startPointX - 5.0, kAnchorHeight)];[self.path addLineToPoint:CGPointMake(startPointX, startPointY)];self.path.lineWidth     = 2.f;self.path.lineCapStyle  = kCGLineCapRound;self.path.lineJoinStyle = kCGLineCapRound;[self.path closePath]; // 封闭未形成闭环的路径UIGraphicsBeginImageContext(self.contentBGImageView.bounds.size);[self.path stroke];UIGraphicsEndImageContext();self.shapeLayer.path = self.path.CGPath;
}

四、点击触摸的mask处理

当下拉菜单显示后,MaskView上实现touchesBegan可以点击触摸可以隐藏菜单,

INNoteZoneOptionMaskView.h

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>@protocol INNoteZoneOptionMaskViewDelegate;
@interface INNoteZoneOptionMaskView : UIView@property (nonatomic, weak) id<INNoteZoneOptionMaskViewDelegate>maskDelegate;@end@protocol INNoteZoneOptionMaskViewDelegate <NSObject>- (void)optionMaskTouched;@end

INNoteZoneOptionMaskView.m

#import "INNoteZoneOptionMaskView.h"@implementation INNoteZoneOptionMaskView- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event {// 1.自己先处理事件...if (self.maskDelegate && [self.maskDelegate respondsToSelector:@selector(optionMaskTouched)]) {[self.maskDelegate optionMaskTouched];}// 2.再调用系统的默认做法,再把事件交给上一个响应者处理[super touchesBegan:touches withEvent:event];
}@end

五、菜单显示

控件显示在keyWindow上

[[UIApplication sharedApplication].keyWindow addSubview:self];

显示动画

- (void)showOption {self.hidden = NO;CGPoint anchorPoint = CGPointMake(self.contentStartPoint.x/self.contentBGImageView.frame.size.width, 0.0);[self resetAnChorPoint:self.contentBGImageView anchorPoint:anchorPoint];self.contentBGImageView.transform = CGAffineTransformMakeScale(0.1, 0.1);[UIView animateWithDuration:0.25 animations:^{self.contentBGImageView.transform = CGAffineTransformMakeScale(1.0, 1.0);self.contentBGImageView.alpha = 1.0;} completion:^(BOOL finished) {}];
}

隐藏菜单

- (void)dismissOption {[UIView animateWithDuration:0.25 animations:^{self.contentBGImageView.transform = CGAffineTransformMakeScale(0.1, 0.1);self.contentBGImageView.alpha = 0.0;} completion:^(BOOL finished) {self.hidden = YES;[self removeFromSuperview];}];
}

五、菜单完整代码

菜单完整代码如下

INNoteZoneOptionView.h

#import <UIKit/UIKit.h>/**元素的item*/
typedef void(^OptionTouchBlock)(void);
@interface INNoteZoneOptionItem : NSObject@property (nonatomic, strong) UIImage *iconImage;
@property (nonatomic, strong) NSString *title;
@property (nonatomic, copy) OptionTouchBlock block;@end/**按钮控件*/
@interface INNoteZoneOptionButton : UIControl@property (nonatomic, strong) UIImage *iconImage;
@property (nonatomic, strong) NSString *title;
@property (nonatomic, assign) BOOL showLine;
@property (nonatomic, strong) INNoteZoneOptionItem *item;@end/**点击➕号的选项操作*/
@interface INNoteZoneOptionView : UIView- (instancetype)initWithFrame:(CGRect)frame anchorPoint:(CGPoint)anchorPoint items:(NSArray *)items;- (void)showOption;- (void)dismissOption;@end

INNoteZoneOptionView.m

#import "INNoteZoneOptionView.h"
#import "UIColor+Addition.h"
#import "UIImageView+WebCache.h"
#import "UIImage+YYAdd.h"
#import "INNoteZoneOptionMaskView.h"#define KCP 3.1415926static CGFloat kOpContentWidth = 130.0;
static CGFloat kOpItemHeight = 50.0;static CGFloat kOpIconSize = 16.0;
static CGFloat kOpMidPadding = 10.0;
static CGFloat kAnchorHeight = 5.0;static CGFloat kBtnMidPadding = 15.0;static CGFloat kBtnPadding = 2.0;
static CGFloat kLineHeight = 1.0;/**元素的item*/
@interface INNoteZoneOptionItem ()@end@implementation INNoteZoneOptionItem@end/**按钮控件*/
@interface INNoteZoneOptionButton ()@property (nonatomic, strong) UIImageView *bgImageView;
@property (nonatomic, strong) UIImageView *iconImageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIImageView *lineImageView;@end@implementation INNoteZoneOptionButton- (instancetype)initWithFrame:(CGRect)frame
{self = [super initWithFrame:frame];if (self) {[self addSubview:self.bgImageView];[self.bgImageView addSubview:self.iconImageView];[self.bgImageView addSubview:self.titleLabel];[self.bgImageView addSubview:self.lineImageView];self.showLine = NO;}return self;
}- (void)layoutSubviews {[super layoutSubviews];self.bgImageView.frame = self.bounds;self.iconImageView.frame = CGRectMake(kBtnMidPadding, (CGRectGetHeight(self.bounds) - kOpIconSize)/2, kOpIconSize, kOpIconSize);self.titleLabel.frame = CGRectMake(CGRectGetMaxX(self.iconImageView.frame) + kBtnMidPadding, 0.0, CGRectGetWidth(self.bgImageView.frame) - (CGRectGetMaxX(self.iconImageView.frame) + kBtnMidPadding*2), CGRectGetHeight(self.bounds));self.lineImageView.frame = CGRectMake(0.0, CGRectGetHeight(self.bgImageView.frame) - kLineHeight, CGRectGetWidth(self.bgImageView.frame), kLineHeight);
}- (void)setIconImage:(UIImage *)iconImage {_iconImage = iconImage;self.iconImageView.image = iconImage;[self setNeedsLayout];
}- (void)setTitle:(NSString *)title {_title = (title?title:@"");self.titleLabel.text = _title;[self setNeedsLayout];
}- (void)setShowLine:(BOOL)showLine {_showLine = showLine;self.lineImageView.hidden = !showLine;[self setNeedsLayout];
}- (void)setHighlighted:(BOOL)highlighted {[super setHighlighted:highlighted];if (highlighted) {self.bgImageView.backgroundColor = [UIColor colorWithHexString:@"f4f4f4"];} else {self.bgImageView.backgroundColor = [UIColor whiteColor];}
}#pragma mark - SETTER/GETTER
- (UIImageView *)iconImageView {if (!_iconImageView) {_iconImageView = [[UIImageView alloc] initWithFrame:CGRectZero];_iconImageView.contentMode = UIViewContentModeScaleAspectFit;}return _iconImageView;
}- (UILabel *)titleLabel {if (!_titleLabel) {_titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];_titleLabel.font = [UIFont boldSystemFontOfSize:14];_titleLabel.textColor = [UIColor colorWithHexString:@"131619"];_titleLabel.backgroundColor = [UIColor clearColor];}return _titleLabel;
}- (UIImageView *)bgImageView {if (!_bgImageView) {_bgImageView = [[UIImageView alloc] initWithFrame:CGRectZero];_bgImageView.backgroundColor = [UIColor whiteColor];_bgImageView.layer.cornerRadius = 2.0;_bgImageView.layer.masksToBounds = YES;}return _bgImageView;
}- (UIImageView *)lineImageView {if (!_lineImageView) {_lineImageView = [[UIImageView alloc] initWithFrame:CGRectZero];_lineImageView.backgroundColor = [UIColor colorWithHexString:@"f1f1f1"];}return _lineImageView;
}@end/**点击➕号的选项操作*/
@interface INNoteZoneOptionView ()<INNoteZoneOptionMaskViewDelegate>@property (nonatomic, strong) INNoteZoneOptionMaskView *maskBGView;
@property (nonatomic, strong) UIImageView *contentBGImageView;
@property (nonatomic, strong) CAShapeLayer *shapeLayer;
@property (nonatomic, strong) UIBezierPath *path;@property (nonatomic) CGPoint anchorPoint;
@property (nonatomic) CGPoint contentStartPoint;
@property (nonatomic, strong) NSArray *items;@end@implementation INNoteZoneOptionView- (instancetype)initWithFrame:(CGRect)frame anchorPoint:(CGPoint)anchorPoint items:(NSArray *)items {self = [super initWithFrame:frame];if (self) {self.anchorPoint = anchorPoint;self.items = items;[self addSubview:self.maskBGView];[self addSubview:self.contentBGImageView];[self.contentBGImageView.layer addSublayer:self.shapeLayer];[[UIApplication sharedApplication].keyWindow addSubview:self];self.frame = [UIScreen mainScreen].bounds;self.hidden = YES;[self layoutOptionSubviews];[self configContentPoint];[self drawShapeLayer];[self setupOptionButtons];}return self;
}- (void)configContentPoint {CGFloat scale = self.anchorPoint.x/self.frame.size.width;CGFloat contentWidth = CGRectGetWidth(self.contentBGImageView.frame);self.contentStartPoint = CGPointMake(scale*contentWidth - kOpMidPadding, 0.0);
}- (void)layoutOptionSubviews {self.maskBGView.frame = self.bounds;self.contentBGImageView.frame = CGRectMake(CGRectGetWidth(self.bounds) - kOpContentWidth - kOpMidPadding, self.anchorPoint.y, kOpContentWidth, self.items.count*kOpItemHeight + kAnchorHeight + 2*kBtnPadding);self.shapeLayer.frame = self.contentBGImageView.bounds;
}#pragma mark - Setup Buttons
- (void)setupOptionButtons {NSInteger index = 0;for (INNoteZoneOptionItem *item in self.items) {INNoteZoneOptionButton *button = [[INNoteZoneOptionButton alloc] initWithFrame:CGRectZero];button.frame = CGRectMake(kBtnPadding, kBtnPadding + kAnchorHeight + index*kOpItemHeight, CGRectGetWidth(self.contentBGImageView.frame) - 2*kBtnPadding, kOpItemHeight);button.iconImage = item.iconImage;button.title = item.title;button.item = item;[self.contentBGImageView addSubview:button];[button addTarget:self action:@selector(optionButtonAction:) forControlEvents:UIControlEventTouchUpInside];button.showLine = YES;if (index == self.items.count - 1) {button.showLine = NO;}index++;}
}- (void)optionButtonAction:(INNoteZoneOptionButton *)button {NSLog(@"点击栏目");if (button.item && button.item.block) {button.item.block();}
}#pragma mark - Show AND Dismiss
- (void)showOption {self.hidden = NO;CGPoint anchorPoint = CGPointMake(self.contentStartPoint.x/self.contentBGImageView.frame.size.width, 0.0);[self resetAnChorPoint:self.contentBGImageView anchorPoint:anchorPoint];self.contentBGImageView.transform = CGAffineTransformMakeScale(0.1, 0.1);[UIView animateWithDuration:0.25 animations:^{self.contentBGImageView.transform = CGAffineTransformMakeScale(1.0, 1.0);self.contentBGImageView.alpha = 1.0;} completion:^(BOOL finished) {}];
}- (void)dismissOption {[UIView animateWithDuration:0.25 animations:^{self.contentBGImageView.transform = CGAffineTransformMakeScale(0.1, 0.1);self.contentBGImageView.alpha = 0.0;} completion:^(BOOL finished) {self.hidden = YES;[self removeFromSuperview];}];
}#pragma mark - ResetAnChorPoint
/**设置动画图钉位置@param view subView*/
- (void)resetAnChorPoint:(UIView *)view anchorPoint:(CGPoint)anchorPoint {CGPoint oldAnchorPoint = view.layer.anchorPoint;view.layer.anchorPoint = anchorPoint;[view.layer setPosition:CGPointMake(view.layer.position.x + view.layer.bounds.size.width * (view.layer.anchorPoint.x - oldAnchorPoint.x), view.layer.position.y + view.layer.bounds.size.height * (view.layer.anchorPoint.y - oldAnchorPoint.y))];
}#pragma mark - INNoteZoneOptionMaskViewDelegate
- (void)optionMaskTouched {[self dismissOption];
}#pragma mark - SETTER/GETTER
- (INNoteZoneOptionMaskView *)maskBGView {if (!_maskBGView) {_maskBGView = [[INNoteZoneOptionMaskView alloc] initWithFrame:CGRectZero];_maskBGView.backgroundColor = [UIColor clearColor];_maskBGView.userInteractionEnabled = YES;_maskBGView.maskDelegate = self;}return _maskBGView;
}- (UIImageView *)contentBGImageView {if (!_contentBGImageView) {_contentBGImageView = [[UIImageView alloc] initWithFrame:CGRectZero];_contentBGImageView.userInteractionEnabled = YES;_contentBGImageView.backgroundColor = [UIColor clearColor];}return _contentBGImageView;
}- (CAShapeLayer *)shapeLayer {if (!_shapeLayer) {_shapeLayer = [CAShapeLayer layer];_shapeLayer.fillColor = [UIColor whiteColor].CGColor;//设置线条的宽度和颜色_shapeLayer.lineWidth = 1.0f;_shapeLayer.strokeColor = [UIColor colorWithHexString:@"9bb9ef" alpha:0.55].CGColor;_shapeLayer.shadowColor = [UIColor colorWithHexString:@"9bb9ef"].CGColor;_shapeLayer.shadowOffset = CGSizeMake(-3, 3);_shapeLayer.shadowOpacity = 0.3;_shapeLayer.shadowRadius = 3.0;}return _shapeLayer;
}#pragma mark - DrawShapeLayer
- (void)drawShapeLayer {CGFloat startPointX = self.contentStartPoint.x;CGFloat startPointY = self.contentStartPoint.y;CGFloat width = CGRectGetWidth(self.contentBGImageView.frame);CGFloat height = CGRectGetHeight(self.contentBGImageView.frame);self.path = [UIBezierPath bezierPath]; // 创建路径[self.path moveToPoint:CGPointMake(startPointX, startPointY)]; // 设置起始点[self.path addLineToPoint:CGPointMake(startPointX + 5.0, kAnchorHeight)];[self.path addLineToPoint:CGPointMake(width - 5.0, kAnchorHeight)];[self.path addArcWithCenter:CGPointMake(width - 5.0, kAnchorHeight + 5.0) radius:5 startAngle:KCP*3/2 endAngle:2*KCP clockwise:YES]; // 绘制一个圆弧[self.path addLineToPoint:CGPointMake(width, height - 5.0)];[self.path addArcWithCenter:CGPointMake(width - 5.0, height - 5.0) radius:5 startAngle:0 endAngle:KCP/2 clockwise:YES]; // 绘制一个圆弧[self.path addLineToPoint:CGPointMake(5, height)];[self.path addArcWithCenter:CGPointMake(5.0, height-5.0) radius:5 startAngle:KCP/2 endAngle:KCP clockwise:YES]; // 绘制一个圆弧[self.path addLineToPoint:CGPointMake(0.0, kAnchorHeight + 5.0)];[self.path addArcWithCenter:CGPointMake(5, kAnchorHeight + 5) radius:5 startAngle:KCP endAngle:KCP*3/2 clockwise:YES]; // 绘制一个圆弧[self.path addLineToPoint:CGPointMake(startPointX - 5.0, kAnchorHeight)];[self.path addLineToPoint:CGPointMake(startPointX, startPointY)];self.path.lineWidth     = 2.f;self.path.lineCapStyle  = kCGLineCapRound;self.path.lineJoinStyle = kCGLineCapRound;[self.path closePath]; // 封闭未形成闭环的路径UIGraphicsBeginImageContext(self.contentBGImageView.bounds.size);[self.path stroke];UIGraphicsEndImageContext();self.shapeLayer.path = self.path.CGPath;
}@end

六、使用显示下拉菜单

使用显示下拉菜单代码,根据anchorPoint确定显示的箭头位置

#pragma mark - INNoteZoneNavbarViewDelegate
- (void)addButtonDidAction:(UIButton *)button {CGRect btnRect = [button convertRect:button.bounds toView:[UIApplication sharedApplication].keyWindow];__weak typeof(self) weakSelf = self;INNoteZoneOptionItem *postItem = [[INNoteZoneOptionItem alloc] init];postItem.iconImage = [UIImage imageNamed:@"ic_op_editpost"];postItem.title = @"发布帖子";postItem.block = ^{NSLog(@"发布帖子");};INNoteZoneOptionItem *scanItem = [[INNoteZoneOptionItem alloc] init];scanItem.iconImage = [UIImage imageNamed:@"ic_op_scan"];scanItem.title = @"扫一扫";scanItem.block = ^{NSLog(@"扫一扫");};INNoteZoneOptionItem *calItem = [[INNoteZoneOptionItem alloc] init];calItem.iconImage = [UIImage imageNamed:@"ic_op_cal"];calItem.title = @"日历";calItem.block = ^{NSLog(@"日历");};INNoteZoneOptionItem *pubWordItem = [[INNoteZoneOptionItem alloc] init];pubWordItem.iconImage = [UIImage imageNamed:@"ic_op_edit"];pubWordItem.title = @"发布美句";pubWordItem.block = ^{NSLog(@"发布美句");};INNoteZoneOptionView *optionView = [[INNoteZoneOptionView alloc] initWithFrame:CGRectZero anchorPoint:CGPointMake(CGRectGetMidX(btnRect), CGRectGetMaxY(btnRect)) items:@[postItem,scanItem,calItem,pubWordItem]];[optionView showOption];
}

七、小结

iOS开发-CAShapeLayer与UIBezierPath实现微信首页的下拉菜单效果。用到了CAShapeLayer与UIBezierPath绘制菜单外框。
学习记录,每天不停进步。

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

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

相关文章

《Elasticsearch 源码解析与优化实战》第5章:选主流程

《Elasticsearch 源码解析与优化实战》第5章&#xff1a;选主流程 - 墨天轮 一、简介 Discovery 模块负责发现集群中的节点&#xff0c;以及选择主节点。ES 支持多种不同 Discovery 类型选择&#xff0c;内置的实现称为Zen Discovery ,其他的包括公有云平台亚马逊的EC2、谷歌…

shell中按照特定字符分割字符串,并且在切分后的每段内容后加上特定字符(串),然后再用特定字符拼接起来

文件中的内容&#xff0c;可以这么写&#xff1a; awk -F, -v OFS, {for(i1;i<‌NF;i){$i$i"_suffix"}}1 input.txt-F,&#xff1a;设置输入字段分隔符为逗号&#xff08;,&#xff09;&#xff0c;这将使awk按照逗号分割输入文本。-v OFS‘,’&#xff1a;设置输…

Banana Pi BPI-CM4 评测(计算模块 4),更快性能,旨在替换树莓派CM4

如果您正在寻找可靠的单板计算机来提升您的下一个项目&#xff0c;但无法找到满足您需求的 Raspberry Pi&#xff0c;请看看我是否可以提供帮助。在这篇详细的评论中&#xff0c;我将向您介绍 Banana Pi CM4&#xff0c;这是一款适用于各种任务的多功能且强大的解决方案。从经验…

GitLab开启双端认证并登录GitLab

GitLab开启双端认证并登录GitLab 1.介绍双端认证 单重认证——密码验证&#xff0c;这极其容易出现密码被盗&#xff0c;密码泄露等危险事件。 于是为了提高安全性&#xff0c;就出现了双因素认证&#xff0c;多因素认证。登录的时候不仅要输入账号和密码还需要输入一个验证码…

使用mediapipe训练手指数字识别

mediapipe手指数字识别 本文是从0开始创建一个识别手势的机器学习模型&#xff0c;为了识别手势&#xff0c;采用mediapipe模型&#xff0c;这个模型会返回手指的位置&#xff0c;之后再通过训练一个模型将这些位置分类得到手势 一、导入依赖 import cv2 import numpy as np…

MD-MTSP:成长优化算法GO求解多仓库多旅行商问题MATLAB(可更改数据集,旅行商的数量和起点)

一、成长优化算法GO 成长优化算法&#xff08;Growth Optimizer&#xff0c;GO&#xff09;由Qingke Zhang等人于2023年提出&#xff0c;该算法的设计灵感来源于个人在成长过程中的学习和反思机制。学习是个人通过从外部世界获取知识而成长的过程&#xff0c;反思是检查个体自…

excel绘制折线图或者散点图

一、背景 假如现在通过代码处理了一批数据&#xff0c;想看数据的波动情况&#xff0c;是不是还需要写个pyhon代码&#xff0c;读取文件&#xff0c;绘制曲线&#xff0c;看起来也简单&#xff0c;但是还有更简单的方法&#xff0c;就是直接生成csv文件&#xff0c;csv文件就是…

【MyBatis】MyBatis 3.5+版本报错合集(持续更新)

报错&#xff1a;BindingException 1. org.apache.ibatis.binding.BindingException: Type interface xxx is not known to the MapperRegistry. 2. org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): xxx 解决方案 在pom.xml中添加如下代码…

python json保留汉字原始形式,而不是Unicode编码(Unicode码)(加ensure_ascii=False参数)

文章目录 问题解决办法测试 问题 如图&#xff0c;保存汉字的时候变成unicode码了。。。 代码是这样的&#xff1a; 解决办法 在Python中&#xff0c;可以使用json模块的ensure_ascii参数来控制是否将汉字转换为类似\u5730\u9707的Unicode编码。默认情况下&#xff0c;ensure…

SpringBoot整合第三方 Druid、MybatisPlus、Mybatis

整合第三方技术 整合JUnit Respostory 注解&#xff1a;数据类 1、导入测试对应的starter 2、测试类使用 SpringBootTest 修饰 3、使用自动装配的形式添加要测试的对象 classes的属性 其实主要找的是SpringBootApplication中的SpringBootConfiguration这个注解。也就是配置…

【Qt】QML-02:QQuickView用法

1、先看demo QtCreator自动生成的工程是使用QQmlApplicationEngine来加载qml文件&#xff0c;下面的demo将使用QQuickView来加载qml文件 #include <QGuiApplication> #include <QtQuick/QQuickView>int main(int argc, char *argv[]) {QGuiApplication app(argc,…

螺旋矩阵 II

给你一个正整数 n &#xff0c;生成一个包含 1 到 n2 所有元素&#xff0c;且元素按顺时针顺序螺旋排列的 n x n 正方形矩阵 matrix 。 示例 1&#xff1a; 输入&#xff1a;n 3 输出&#xff1a;[[1,2,3],[8,9,4],[7,6,5]] 示例 2&#xff1a; 输入&#xff1a;n 1 输出&a…

JGJ59-2011建筑施工安全检查标准

为科学评价建筑施工现场安全生产&#xff0c;预防生产安全事故的发生&#xff0c;保障施工人员的安全和健康&#xff0c;提高施工管理水平&#xff0c;实现安全检查工作的标准化&#xff0c;制定本标准。 本标准适用于房屋建筑工程施工现场安全生产的检查评定。 建筑施工安全…

7.28 作业 QT

手动完成服务器的实现&#xff0c;并具体程序要注释清楚: widget.h: #ifndef WIDGET_H #define WIDGET_H#include <QWidget> #include <QTcpServer> //服务器类 #include <QTcpSocket> //客户端类 #include <QMessageBox> //对话框类 #include …

更安全,更省心丨DolphinDB 数据库权限管理系统使用指南

在数据库产品使用过程中&#xff0c;为保证数据不被窃取、不遭破坏&#xff0c;我们需要通过用户权限来限制用户对数据库、数据表、视图等功能的操作范围&#xff0c;以保证数据库安全性。为此&#xff0c;DolphinDB 提供了具备以下主要功能的权限管理系统&#xff1a; 提供用户…

附录1-将uni-app运行到微信开发者工具

目录 1 在manifest.json写入AppID 2 配置微信开发者工具的安装路径 3 微信开发者工具的安全设置 4 运行 5 修改一些配置项 1 在manifest.json写入AppID 2 配置微信开发者工具的安装路径 如果你忘了安装在哪里了&#xff0c;可以右键快捷方式看一下属性 在运行设置…

Modbus TCP使用例程

一、Modbus介绍 关于Modbus的介绍可参考前面的文章<modbus tcp协议介绍及分析>和<modbus rtu通信格式测试解析>这2篇文章。 二、Agile Modbus软件包介绍 Agile Modbus软件包的链接地址&#xff1a; https://gitee.com/RT-Thread-Mirror/agile_modbus Agile Modbus的…

多线程之GCD应用

一些套话 GCD全称是Grand Central Dispatch&#xff0c;它是纯 C 语言&#xff0c;并且提供了非常多强大的函数 GCD的优势&#xff1a; GCD 是苹果公司为多核的并行运算提出的解决方案GCD 会自动利用更多的CPU内核&#xff08;比如双核、四核&#xff09;GCD 会自动管理线程的…

DSSAT模型教程

详情点击链接&#xff1a;R语言与作物模型&#xff08;DSSAT模型&#xff09;教程 前言 随着基于过程的作物生长模型&#xff08;Process-based Crop Growth Simulation Model&#xff09;的发展&#xff0c;R语言在作物生长模型和数据分析、挖掘和可视化中发挥着越来越重要的…

数据结构基础之二叉树

文章目录 二叉树性质二叉树分类遍历二叉树如何判断是否为完全二叉树 二叉树是树形结构的一个重要类型。许多实际问题抽象出来的数据结构往往是二叉树形式&#xff0c;即使是一般的树也能简单地转换为二叉树&#xff0c;而且二叉树的存储结构及其算法都较为简单&#xff0c;因此…