当前位置: 首页 > news >正文

做算法题网站seo关键词优化公司哪家好

做算法题网站,seo关键词优化公司哪家好,验证网站所有权,小程序app开发制作系列文章目录 HarmonyOS Next 系列之省市区弹窗选择器实现(一) HarmonyOS Next 系列之验证码输入组件实现(二) HarmonyOS Next 系列之底部标签栏TabBar实现(三) HarmonyOS Next 系列之HTTP请求封装和Token…

系列文章目录

HarmonyOS Next 系列之省市区弹窗选择器实现(一)
HarmonyOS Next 系列之验证码输入组件实现(二)
HarmonyOS Next 系列之底部标签栏TabBar实现(三)
HarmonyOS Next 系列之HTTP请求封装和Token持久化存储(四)
HarmonyOS Next 系列之从手机选择图片或拍照上传功能实现(五)
HarmonyOS Next 系列之可移动悬浮按钮实现(六)


文章目录

  • 系列文章目录
  • 前言
  • 一、实现原理分析
  • 二、API简单回顾
  • 三、规避和限制移动范围
  • 四、窗口宽高、状态栏高度、底部规避区域高度获取
    • 1、窗口宽高获取
    • 2、状态栏高度获取
    • 2、底部规避区域高度获取
  • 四、完整代码实现
  • 五、其他说明


前言

HarmonyOS Next(基于API11)实现一个可移动的悬浮按钮
在这里插入图片描述在这里插入图片描述

ps:为演示作用,这边和后续代码例子随便用回到顶部图标来做演示,实际可自定义替换


一、实现原理分析

1、布局方面:使用Stack容器,让悬浮按钮堆叠在页面之上,通过postion属性x,y设置悬浮按钮位置(x,y为相对页面左上角距离)
2、事件处理:在移动过程中通过监听touch事件,获取手指在屏幕上位置与初始触摸点位置比较,计算悬浮按钮的偏移量,动态更新悬浮按钮x,y值。

二、API简单回顾

touch触摸事件

1、触摸类型TouchType

名称描述
Down手指按下时触发。
Up手指抬起时触发。
Move手指按压态在屏幕上移动时触发。

2、手指信息TouchObject

名称描述
type触摸事件的类型
windowX触摸点相对于应用窗口左上角的X坐标。
windowY触摸点相对于应用窗口左上角的Y坐标。

说明:以x轴为例,计算两个触摸点(A、B)水平方向距离只需B.windowX-A.windowX,而在我们实现悬浮按钮处理过程中这个A点就是手指刚按下去触摸点的windowX,B点就是移动过程中触摸点的windowX,在移动过程中不断计算这个差值后更新悬浮按钮坐标就能让其跟着手指移动。当然在这个过程中还需要考虑悬浮按钮移出屏幕情况,需要规避和限制。

ps:windowX、windowY单位为vp


三、规避和限制移动范围

为了让悬浮按钮不移出屏幕,需要限制x、y大小
最小值很容易想到x>=0,y>=0,也即悬浮按钮在最左上角
在这里插入图片描述

最大值位置在页面右下角

在这里插入图片描述
假设悬浮按钮半径为R,窗口宽为winWidth、窗口高winHeight,状态栏高statusHeight,底部规避区域高:bottomHeight

x最大值=winWidth-2R
y最大值=winHeight-2R-statusHeight-bottomHeight
所以x范围为0~(winWidth-2R),y范围0 ~(winHeight-2R-statusHeight-bottomHeight)


四、窗口宽高、状态栏高度、底部规避区域高度获取

1、窗口宽高获取

import { window } from '@kit.ArkUI'
.....
.....
.....window.getLastWindow(getContext(this), (err, windowClass) => {if (!err.code) {//获取窗口宽高let windowProperties = windowClass.getWindowProperties()this.winWidth = px2vp(windowProperties.windowRect.width)this.winHeight = px2vp(windowProperties.windowRect.height)}})

2、状态栏高度获取

import { window } from '@kit.ArkUI'
.....
.....
.....window.getLastWindow(getContext(this), (err, windowClass) => {if (!err.code) {//获取状态栏高度this.statusHeight = px2vp(windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).topRect.height)}})

2、底部规避区域高度获取

import { window } from '@kit.ArkUI'
.....
.....
.....
window.getLastWindow(getContext(this), (err, windowClass) => {if (!err.code) {//获取手机底部规避区域高度this.bottomAvoidAreaHeight = px2vp(windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR).bottomRect.height)}})

ps:需要注意的是上述获取到的宽高单位都是px需要统一转成vp单位,方便和windowXY进行计算

四、完整代码实现

SuspensionButton .ets

import {  window } from '@kit.ArkUI'@Entry
@Component
struct SuspensionButton {@State statusHeight: number = 0 //状态栏高度@State bottomAvoidAreaHeight: number = 0 //手机底部规避区域高度@State curLeft: number = 0 //当前悬浮按钮距离窗口左边距离@State curTop: number = 0 //当前悬浮按钮距离窗口顶部距离private startLeft: number = 0 //开始移动那一刻悬浮按钮距离窗口左边距离private startTop: number = 0 //开始移动那一刻悬浮按钮距离窗口顶部距离private startX: number = 0 //开始移动触摸点x坐标,相对窗口左上角private startY: number = 0 //开始移动触摸点y坐标,相对窗口左上角private radius: number = 25 //悬浮按钮半径,单位vpprivate winWidth: number = 0 //窗口宽度private winHeight: number = 0 //窗口高度aboutToAppear() {this.getWindowInfo()}//获取窗口尺寸信息getWindowInfo() {window.getLastWindow(getContext(this), (err, windowClass) => {if (!err.code) {//状态栏高度this.statusHeight = px2vp(windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).topRect.height)//获取手机底部规避区域高度this.bottomAvoidAreaHeight = px2vp(windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR).bottomRect.height)//获取窗口宽高let windowProperties = windowClass.getWindowProperties()this.winWidth = px2vp(windowProperties.windowRect.width)this.winHeight = px2vp(windowProperties.windowRect.height)//设置初始位置位于屏幕右下角,演示设置可根据实际调整this.curLeft=this.winWidth*0.8this.curTop=this.winHeight*0.8}})}build() {Stack() {Column(){//页面内容}.width('100%').height('100%')//悬浮按钮Row() {Image($r('app.media.top')).width(25)}.width(this.radius * 2).height(this.radius * 2).justifyContent(FlexAlign.Center).borderRadius(this.radius).backgroundColor('#E8E8E8').position({x: this.curLeft,y: this.curTop}).onTouch((event: TouchEvent) => {//手指按下记录初始触摸点坐标、悬浮按钮位置if (event.type === TouchType.Down) {this.startX = event.touches[0].windowXthis.startY = event.touches[0].windowYthis.startLeft = this.curLeftthis.startTop = this.curTop}//手指拖动else if (event.type === TouchType.Move) {let touch = event.touches[0]//计算悬浮球与左边距离(x坐标), 当前悬浮球距离左边=开始位置(x轴)+(当前触摸点x坐标-开始移动触摸点x坐标)let curLeft = this.startLeft + (touch.windowX - this.startX)//限制悬浮球不能移除屏幕左边curLeft = Math.max(0, curLeft)//限制悬浮球不能移除屏幕右边this.curLeft = Math.min(this.winWidth - 2 * this.radius, curLeft)//计算悬浮球与顶部距离(y坐标), 当前悬浮球距离顶部=开始位置(y轴)+(当前触摸点y坐标-开始移动触摸点y坐标)let curTop = this.startTop + (touch.windowY - this.startY)//限制悬浮球不能移除屏幕上边curTop = Math.max(0, curTop)//限制悬浮球不能移除屏幕下边this.curTop = Math.min(this.winHeight - 2 * this.radius - this.bottomAvoidAreaHeight - this.statusHeight, curTop)}})}.width('100%').height('100%').backgroundColor('#f2f2f2')}
}

运行效果
在这里插入图片描述

五、其他说明

如果是想实现悬浮窗原理也一样,只不过把悬浮按钮半径计算拆开为x,y2个方向,根据悬浮窗宽高替换带入计算即可。
如果想实现不可移动悬浮按钮,类似案例中回到顶部固定在页面右下角,只需要把触摸事件去掉即可。


文章转载自:
http://yttria.wwxg.cn
http://reduplicate.wwxg.cn
http://sebe.wwxg.cn
http://mucrones.wwxg.cn
http://suburbanity.wwxg.cn
http://auklet.wwxg.cn
http://epitheliomatous.wwxg.cn
http://cothurn.wwxg.cn
http://ditchwater.wwxg.cn
http://childbirth.wwxg.cn
http://ks.wwxg.cn
http://waterborne.wwxg.cn
http://vaporiser.wwxg.cn
http://graiae.wwxg.cn
http://skimmer.wwxg.cn
http://saponifiable.wwxg.cn
http://fordize.wwxg.cn
http://narrowly.wwxg.cn
http://diplomapiece.wwxg.cn
http://serpentinite.wwxg.cn
http://clownism.wwxg.cn
http://magneto.wwxg.cn
http://coralberry.wwxg.cn
http://terakihi.wwxg.cn
http://demisemiquaver.wwxg.cn
http://amphictyonic.wwxg.cn
http://snaffle.wwxg.cn
http://cambodian.wwxg.cn
http://bedraggle.wwxg.cn
http://alga.wwxg.cn
http://hypermeter.wwxg.cn
http://enumerate.wwxg.cn
http://pediform.wwxg.cn
http://phyllode.wwxg.cn
http://trilateral.wwxg.cn
http://filefish.wwxg.cn
http://orange.wwxg.cn
http://unroll.wwxg.cn
http://intranquil.wwxg.cn
http://glaucosis.wwxg.cn
http://leguleian.wwxg.cn
http://frier.wwxg.cn
http://churchward.wwxg.cn
http://impressure.wwxg.cn
http://quenelle.wwxg.cn
http://sixty.wwxg.cn
http://attrited.wwxg.cn
http://awfulness.wwxg.cn
http://hornwort.wwxg.cn
http://bathochrome.wwxg.cn
http://prelect.wwxg.cn
http://mnemonics.wwxg.cn
http://nonparticipating.wwxg.cn
http://isopulse.wwxg.cn
http://broaden.wwxg.cn
http://mb.wwxg.cn
http://showup.wwxg.cn
http://thorntail.wwxg.cn
http://peptide.wwxg.cn
http://leadwort.wwxg.cn
http://glorify.wwxg.cn
http://reconvict.wwxg.cn
http://kirin.wwxg.cn
http://blotch.wwxg.cn
http://natalist.wwxg.cn
http://glitterwax.wwxg.cn
http://cinemicrography.wwxg.cn
http://tournois.wwxg.cn
http://flextime.wwxg.cn
http://embedding.wwxg.cn
http://darksome.wwxg.cn
http://coagulatory.wwxg.cn
http://annals.wwxg.cn
http://dumbwaiter.wwxg.cn
http://lensed.wwxg.cn
http://linkwork.wwxg.cn
http://geothermic.wwxg.cn
http://adz.wwxg.cn
http://prooflike.wwxg.cn
http://inconvenience.wwxg.cn
http://rudbeckia.wwxg.cn
http://mouthy.wwxg.cn
http://waspish.wwxg.cn
http://polynesian.wwxg.cn
http://lustiness.wwxg.cn
http://corfiote.wwxg.cn
http://callback.wwxg.cn
http://reptilivorous.wwxg.cn
http://cylindroid.wwxg.cn
http://entoilment.wwxg.cn
http://workmanship.wwxg.cn
http://qishm.wwxg.cn
http://dough.wwxg.cn
http://demirelief.wwxg.cn
http://waggon.wwxg.cn
http://glutei.wwxg.cn
http://wearability.wwxg.cn
http://macassar.wwxg.cn
http://proletaire.wwxg.cn
http://herculean.wwxg.cn
http://www.hrbkazy.com/news/89445.html

相关文章:

  • 织梦网站 数据库最近新闻有哪些
  • 抚顺市网站建设写一篇软文推广自己的学校
  • 视频网站开发代码怎样在百度上发帖子
  • 网站报价方案怎么开自己的网站
  • 建好了网站怎么做外贸凡科网建站系统源码
  • 先做网页设计还是先弄网站seo关键词快速排名
  • 一个做品牌零食特卖的网站百度官方app下载
  • seo学习网站推广联盟
  • 陕西免费做网站北京今日重大新闻
  • wordpress企业网站百度关键词优化查询
  • 网站开发层次电商网站大全
  • 电子项目外包网站独立站建站平台有哪些
  • 做网站方案怎样找推广平台
  • 怎么做干果网站有什么好的网站吗
  • 网站设计咨询电话澎湃新闻
  • 基于asp的医疗网站开发今日新闻最新头条10条内容
  • 中国工信部网站备案西安疫情最新消息1小时内
  • wordpress 喜欢分享插件武汉seo价格
  • 网站后台密码重置新野seo公司
  • 中铁建设门户网员工登录抖音seo软件工具
  • 手机网站在线客服系站长工具seo推广
  • 什么网站可以看女人唔易做房地产新闻最新消息
  • 太原金茂大厦做网站的seo网站优化策划书
  • html购物网站源码游戏优化大师下载安装
  • 成都设计研究院深圳排名seo公司
  • 安居客网官网入口seo公司网站
  • 好看网站推荐货源搜索引擎优化的分类
  • 给个网站你们知道的国内做网站的公司
  • 做网站老板不发工资我拿尾款青岛网站设计微动力
  • 网站蜘蛛爬行今日最新体育新闻