提交 a05f1bcd 编写于 作者: lizhongyi_'s avatar lizhongyi_

feat: iOS增加获取本地资源路径Api支持,及其示例页面

上级 2260eb50
......@@ -97,7 +97,17 @@
"enablePullDownRefresh": false
}
},{
},
{
"path" : "pages/advance/iOS/getResourcePath",
"style" :
{
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
},
{
"path" : "pages/advance/android/assetaudio",
"style" :
{
......
......@@ -45,6 +45,12 @@
</uni-list>
</uni-collapse-item>
<uni-collapse-item title="iOS平台示例" :border="false">
<uni-list>
<uni-list-item @tap="testGetResourcePath" title="资源路径获取示例" :clickable="true" link />
</uni-list>
</uni-collapse-item>
</uni-collapse>
......@@ -161,6 +167,11 @@
url: '/pages/SyntaxCase/index'
})
},
testGetResourcePath: function() {
uni.navigateTo({
url: '/pages/advance/iOS/getResourcePath'
})
}
}
}
......
<template>
<view>
<page-head title="资源路径获取示例" accordion></page-head>
<button @tap="getResourcePath">获取本地资源路径</button>
</view>
</template>
<script>
import { getResourcePath } from '@/uni_modules/uts-advance'
import { removeExampleImageView } from '@/uni_modules/uts-advance'
export default {
onUnload() {
removeExampleImageView()
},
methods:{
getResourcePath(){
getResourcePath("/static/logo.png")
}
}
}
</script>
<style>
.text-box {
margin-bottom: 40rpx;
padding: 40rpx 0;
display: flex;
min-height: 300rpx;
background-color: #FFFFFF;
justify-content: center;
align-items: center;
text-align: center;
font-size: 30rpx;
color: #353535;
line-height: 1.8;
}
</style>
import { UIImageView , UIImage , UIScreen } from 'UIKit';
import { DispatchQueue } from 'Dispatch';
export function addViewToDecorView() { }
export function removeViewToDecorView() { }
export function initAppLifecycle() { }
......@@ -53,4 +55,50 @@ export function clearIntervalTask(taskId:number) {
clearInterval(taskId);
return { name: "clearIntervalTask"};
}
/*
* 保存全局数据信息
*/
class AdvanceModuleGloabInfo {
static imageView?: UIImageView = null
}
/**
* 将h5资源路径转成app本地资源路径
*/
export function getResourcePath(path: string) {
const imagePath = UTSiOS.getResourcePath(path)
console.log(imagePath)
if (AdvanceModuleGloabInfo.imageView == null) {
let vc = UTSiOS.getCurrentViewController()
// uts方法默认会在子线程中执行,涉及 UI 操作必须在主线程中运行,通过 DispatchQueue.main.async 方法可将代码在主线程中运行
DispatchQueue.main.async(execute=():void => {
// 创建imageView
let imageView = new UIImageView()
let image = new UIImage(contentsOfFile = imagePath)
imageView.image = image
// 添加imageView并设置frame
vc.view.addSubview(imageView)
let imageSize = 80.0
let midx = (UIScreen.main.bounds.size.width - imageSize) / 2
let midy = (UIScreen.main.bounds.size.height - imageSize) / 2
imageView.frame = CGRect(x = midx, y = midy, width = imageSize, height = imageSize)
AdvanceModuleGloabInfo.imageView = imageView
})
}
}
export function removeExampleImageView() {
DispatchQueue.main.async(execute=():void => {
if (AdvanceModuleGloabInfo.imageView != null) {
AdvanceModuleGloabInfo.imageView!.removeFromSuperview()
AdvanceModuleGloabInfo.imageView = null
}
})
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册