提交 e320aef6 编写于 作者: Z zhangrao

add image

Signed-off-by: Nzhangrao <zhangrao@huawei.com>
上级 dc349576
// @ts-nocheck
/**
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import events_emitter from '@ohos.emitter'
@Entry
@Component
struct PanGestureExample {
@State offsetX: number = 0
@State offsetY: number = 0
@State direction: PanDirection = All
build() {
Flex({ direction: FlexDirection.Column, direction:this.direction, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text('PanGesture offset:\nX: ' + this.offsetX + '\n' + 'Y: ' + this.offsetY)
}
.key('swipeDirection')
.height(100).width(200).padding(20).border({ width: 1 }).margin(80)
.translate({ x: this.offsetX, y: this.offsetY, z: 5 })
.gesture(
PanGesture({})
.onActionStart((event: PanGestureEvent) => {
console.info('Pan start')
})
.onActionUpdate((event: PanGestureEvent) => {
this.offsetX = event.offsetX
this.offsetY = event.offsetY
})
.onActionEnd(() => {
console.info('Pan end')
})
)
}
onPageShow() {
console.info('panDirection page show called');
var stateChangeEvent = {
eventId: 167,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack)
}
private stateChangCallBack = (eventData) => {
if (eventData != null) {
console.info("panDirection page state change called:" + JSON.stringify(eventData));
if (eventData.data.direction != null) {
this.direction = eventData.data.direction;
}
}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册