1.如何實(shí)現(xiàn)遮罩效果
使用onTouch實(shí)現(xiàn)按下抬起事件,.mask()實(shí)現(xiàn)遮罩的效果。代碼如下:
@Entry
@Component
struct Index {
@State mask:boolean=false
build() {
Column() {
Image('/comment/bg.jpg')
.mask(this.mask?new Rect({ width: '500px', height: '280px' }).fill(Color.Gray):null)
.width('500px').height('280px')
.onTouch((event: TouchEvent) => {
switch(event.type){
case TouchType.Down:
this.mask=true
break;
case TouchType.Up:
this.mask=false
break;
}
})
}.width('100%').margin({ top: 5 })
}
}
2.使用藍(lán)湖時(shí),eTS單位的換算
eTS默認(rèn)使用的單位是vp,將px轉(zhuǎn)vp:
px:屏幕物理像素單位。
vp:屏幕密度相關(guān)像素,根據(jù)屏幕像素密度轉(zhuǎn)換為屏幕物理像素
ppi:屏幕像素點(diǎn)密度(Pixels Per Inch-PPI),對(duì)角線(xiàn)像素點(diǎn)個(gè)數(shù)/屏幕尺寸。 即每英寸中有多少個(gè)像素點(diǎn)。
vp=(px*160)/PPI
PS:乘以160是因?yàn)樵谝恍┩ㄓ闷聊幌?60像素密度下剛好1vp=1px;
備注:各屏幕密度如下
![poYBAGLOHY2AC_nhAAALb9Sjp04813.png](https://file.elecfans.com//web2/M00/52/66/poYBAGLOHY2AC_nhAAALb9Sjp04813.png)
320*480(120<160),以此類(lèi)推,密度為420會(huì)歸到1080x1920里面<>
3.ets聲明式ui開(kāi)發(fā),怎么獲取當(dāng)前系統(tǒng)時(shí)間
在這里,我們將字符串用@state包裹,這樣可以監(jiān)聽(tīng)數(shù)據(jù)的更新
我們給Text綁定點(diǎn)擊時(shí)間,然后點(diǎn)擊,即可顯示當(dāng)前時(shí)間,下面是效果。
![pYYBAGLOHY2Af8keAAB2DMAuX_s539.png](https://file.elecfans.com//web2/M00/53/02/pYYBAGLOHY2Af8keAAB2DMAuX_s539.png)
@Entry
@Component
struct Index {
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold).onClick(()=>{
let date = new Date()
//獲取當(dāng)前時(shí)間
// this.message=date.toLocaleString();
//周幾
// this.message=date.getUTCDay().toString();
//日期
// this.message=date.getUTCDate().toString();
// //農(nóng)歷月份
// this.message=date.getUTCMonth().toString();
this.message=date.getFullYear() + "年" + (date.getMonth() + 1) + "月" + date.getDate() + "日" + date.getHours() + "時(shí)" + date.getMinutes() + "分" + date.getSeconds()+ "秒"
})
}
.width('100%')
}
.height('100%')
}
}
4.aboutToAppear和onAppear的區(qū)別?
aboutToAppear:是被@Component修飾自定義組件的生命周期方法,函數(shù)在創(chuàng)建自定義組件的新實(shí)例后,在執(zhí)行其build函數(shù)之前執(zhí)行。
onAppear:是每個(gè)組件的屬性方法,在該組件顯示時(shí)觸發(fā)此回調(diào)。
審核編輯:湯梓紅
-
HarmonyOS
+關(guān)注
關(guān)注
79文章
1983瀏覽量
30642 -
OpenHarmony
+關(guān)注
關(guān)注
25文章
3753瀏覽量
16671
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
飛思卡爾 KL 系列常見(jiàn)問(wèn)題和解答匯總篇
英飛凌IGBT應(yīng)用常見(jiàn)問(wèn)題解答
Window7遠(yuǎn)程桌面連接Ubuntu14.04常見(jiàn)問(wèn)題?
三菱PLC之間的N:N無(wú)線(xiàn)通訊的常見(jiàn)問(wèn)題匯總
C語(yǔ)言常見(jiàn)問(wèn)題合集匯總
直放站常見(jiàn)問(wèn)題及分析
![直放站<b class='flag-5'>常見(jiàn)問(wèn)題</b>及分析](https://file.elecfans.com/web2/M00/48/B2/pYYBAGKhtBmAbJMsAACFv8JBV0k899.jpg)
Keil編譯常見(jiàn)問(wèn)題
SIM900A常見(jiàn)問(wèn)題匯總,奉上解決方案
固德威逆變器wifi設(shè)置_方法步驟教程_常見(jiàn)問(wèn)題匯總
![固德威逆變器wifi設(shè)置_方法步驟教程_<b class='flag-5'>常見(jiàn)問(wèn)題</b><b class='flag-5'>匯總</b>](https://file.elecfans.com/web1/M00/50/C4/o4YBAFr6lGGAFQJfAABGZWnOQ_Q317.jpg)
評(píng)論