HarmonyOS鸿蒙Next中UI的gesture事件中调用持有实例的方法报Error message:is not callable
HarmonyOS鸿蒙Next中UI的gesture事件中调用持有实例的方法报Error message:is not callable
// index.ets
import { AREngine, Gesture } from '../model/AREngine';
@Entry
@Component
struct Index {
@State message: string = 'AR World';
engine = new AREngine();
build() {
Column() {
Text(this.message)
}
.width('100%')
.height('100%')
.gesture(
GestureGroup(GestureMode.Parallel,
PanGesture()
.onActionStart((event: GestureEvent) => {
this.engine.onGestureEvent(event, Gesture.PanBegin)
}),
PinchGesture()
.onActionStart((event: GestureEvent) => {
this.engine.onGestureEvent(event, Gesture.PinBegin)
})
)
)
}
}
// AREngine.ets
export enum Gesture {
PanBegin,
PanUpdate,
PanEnd,
PinBegin,
PinUpdate,
PinEnd,
RotateBegin,
RotateUpdate,
RotateEnd,
}
export class AREngine {
private mShadow: bigint = 0n;
...
onGestureEvent(event: GestureEvent, eventType: Gesture) {
switch (eventType) {
case Gesture.PanBegin:
console.info(this.mShadow + ' on PanBegin: ' + JSON.stringify(event));
// ... 其他cases处理
}
}
}
报错信息如下
Reason:TypeError
Error name:TypeError
Error message:is not callable
Stacktrace:
at anonymous (entry/src/main/ets/pages/Index.ets:14:19)
at updateFunc
at observeComponentCreation2
at initialRender (entry/src/main/ets/pages/Index.ets:9:3)
at initialRenderView更多关于HarmonyOS鸿蒙Next中UI的gesture事件中调用持有实例的方法报Error message:is not callable的实战教程也可以访问 https://www.itying.com/category-93-b0.html
尊敬的开发者,您好!您的问题已受理,请您耐心等待,感谢您的理解与支持!
更多关于HarmonyOS鸿蒙Next中UI的gesture事件中调用持有实例的方法报Error message:is not callable的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
已解决,枚举类Gesture声明为const就可以正常运行了,只能说问题点跟堆栈报错信息几乎看不出关联,也不知道为什么不加const就会导致程序jscrash闪退
export const enum Gesture {
PanBegin,
...
}
在HarmonyOS鸿蒙Next中,UI的gesture事件调用持有实例方法报"is not callable"错误,通常是因为方法绑定丢失或作用域问题。需检查方法是否正确定义为实例成员,并在gesture回调中通过正确的作用域引用。使用箭头函数或bind方法确保this指向正确实例。避免直接传递方法名,需确保调用时方法确实存在于当前对象实例上。


