未复现出切横屏后调到下一个元素的问题,可以按以下demo排查下import { window } from '@kit.ArkUI' class MyDataSource implements IDataSource { private list: number[] = [] constructor(list: number[]) { this.list = list } totalCount(): number { return this.list.length } getData(index: number): number { return this.list[index] } registerDataChangeListener(listener: DataChangeListener): void { } unregisterDataChangeListener() { } } const TAG = 'foo' @Entry @Component struct SwiperExample { private swiperController: SwiperController = new SwiperController() private data: MyDataSource = new MyDataSource([]) aboutToAppear(): void { let list: number[] = [] for (let i = 1; i <= 10; i++) { list.push(i); } this.data = new MyDataSource(list) } setOrientation() { try { window.getLastWindow(getContext(this), (err, data) => { // 获取window实例 if (err.code) { console.error(TAG, 'Failed to obtain the top window. Cause: ' + JSON.stringify(err)); return; } let windowClass = data; console.info(TAG, 'Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); let orientation = window.Orientation.LANDSCAPE; // 设置窗口方向为传感器自动旋转模式。 try { windowClass.setPreferredOrientation(orientation, (err) => { if (err.code) { console.error(TAG, 'Failed to set window orientation. Cause: ' + JSON.stringify(err)); return; } console.info(TAG, 'Succeeded in setting window orientation.'); }); } catch (exception) { console.error(TAG, 'Failed to set window orientation. Cause: ' + JSON.stringify(exception)); } }); } catch (exception) { console.error(TAG, 'Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); } } build() { Column({ space: 5 }) { Swiper(this.swiperController) { LazyForEach(this.data, (item: string) => { Text(item.toString()) .width('90%') .height(160) .backgroundColor(0xAFEEEE) .textAlign(TextAlign.Center) .fontSize(30) Button('转').onClick(() => { this.setOrientation(); }) }, (item: string) => item) } .cachedCount(2) .index(1) .autoPlay(true) .interval(4000) .loop(true) .indicatorInteractive(true) .duration(1000) .itemSpace(0) .indicator( // 设置圆点导航点样式 new DotIndicator() .itemWidth(15) .itemHeight(15) .selectedItemWidth(15) .selectedItemHeight(15) .color(Color.Gray) .selectedColor(Color.Blue)) .displayArrow({ // 设置导航点箭头样式 showBackground: true, isSidebarMiddle: true, backgroundSize: 24, backgroundColor: Color.White, arrowSize: 18, arrowColor: Color.Blue }, false) .curve(Curve.Linear) Row({ space: 12 }) { Button('showNext') .onClick(() => { this.swiperController.showNext() }) Button('showPrevious') .onClick(() => { this.swiperController.showPrevious() }) }.margin(5) }.width('100%') .margin({ top: 5 }) } }
未复现出切横屏后调到下一个元素的问题,可以按以下demo排查下