关于rotate动画在ios设备无效的问题

在创建扑克牌旋转效果时,遇到一个奇怪的问题:该效果在Chrome和Android设备上正常,但在iOS设备上无法显示。尝试添加CSS前缀并未解决问题。经过一番研究,发现在Safari 8.0及以上版本中,rotate3d不被支持,但rotateX和rotateY是可行的。通过调整代码,最终成功实现了在iOS设备上的旋转动画。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近在一个页面里做一个扑克牌的旋转效果,测试的时候发现,在chrome上和Android设备上旋转效果都是没问题的,但是在ios设备上就完全没效果,这可急坏了宝宝,网上各路大神给的解决方案都是加上-webkit-前缀就可以,但是我试了一下,还是没有效果,之后就开始一路寻找破解方案之路。
这是我开始的代码

.animation3d {
    animation:rotate 0.2s infinite linear;
}
@keyframes rotate{
    0%{
        transform: rotate3d(0,1,0,0deg);
    }
    100%{
        transform: rotate3d(0,1,0,360deg);
    }
}

后来加了前缀

.animation3d {
    -webkit-animation:rotate 0.2s infinite linear;
    animation:rotate 0.2s infinite linear;
}
@-webkit-keyframes rotate{
    0%{
        -webkit-transform: rotate3d(0,1,0,0deg);
    }
    100%{
        -webkit-transform: rotate3d(0,1,0,360deg);
    }
}
@keyframes rotate{
    0%{
        transform: rotate3d(0,1,0,0deg);
    }
    100%{
        transform: rotate3d(0,1,0,360deg);
    }
}

可是加上了之后也无济于事…,在兽兽的帮助下,看了无数个帖子分享和属性说明之后,我对代码做了些微改动

.animation3d {
    -webkit-animation:rotate 0.2s infinite linear;
    animation:rotate 0.2s infinite linear;
}
@-webkit-keyframes rotate{
    0%{
        -webkit-transform: rotate3Y(0deg);
    }
    100%{
        -webkit-transform: rotateY(360deg);
    }
}
@keyframes rotate{
    0%{
        transform: rotateY(0deg);
    }
    100%{
        transform: rotateY(360deg);
    }
}

你是想不到啊,它居然就动了!!真的动了!
rotate在Safari8.0以上应该是完全支持的,但是不知道为什么rotate3d怎么都不支持,还好rotateX 和rotateY还是支持的,所以解决了我的问题

reset() { // 1. 强制停止所有状态 console.log('停止所有状态'); this.isPlaying = false; this.isPaused = false; this.currentIndex = 0; // 2. 清除所有动画 if (this.animationTimer) { console.log('清除动画定时器'); clearTimeout(this.animationTimer); this.animationTimer = null; } // 3. 检查数据有效性 if (!this.coordinate || this.coordinate.length === 0) { console.warn('无有效坐标数据'); return; } const startPoint = this.coordinate[0]; console.log('起始点坐标:', startPoint); // 4. 双重更新策略(关键修改) this.$set(this.covers, 0, { ...this.covers[0], latitude: startPoint.latitude, longitude: startPoint.longitude, rotate: 0, }); console.log('更新 covers 数组中的位置:', this.covers); this.covers = [{ id: 1, latitude: startPoint.latitude, longitude: startPoint.longitude, // #ifdef MP-WEIXIN width: 20, height: 20, rotate: 0, iconPath: '../../static/cheche.png', // #endif // #ifdef APP-PLUS width: 5, height: 5, rotate: 0, iconPath: '../../static/chechex3.png', // #endif anchor: { x: 0.55, y: 0.55, }, }]; console.log('更新后的 covers:', this.covers); // 5. 强制地图刷新(多平台兼容) this.$nextTick(() => { console.log('触发 nextTick,准备更新地图'); if (!this.map) { console.log('创建 map 实例'); this.map = uni.createMapContext('map', this); } // 方法2:标记位置更新(微信小程序必需) console.log('调用 translateMarker 更新标记位置'); this.map.translateMarker({ markerId: 1, destination: { latitude: startPoint.latitude, longitude: startPoint.longitude }, rotate: 0, duration: 0, }); }); // 微信小程序特殊处理(关键) // #ifdef MP-WEIXIN setTimeout(() => { if (this.map.updateComponents) { console.log('调用 updateComponents 强制刷新地图'); this.map.updateComponents(); } this.map.updateComponents && this.map.updateComponents(); console.log('微信地图强制刷新111111'); }, 500); // #endif } duration: 0,时 苹果微信小程序轨迹回放图标不会回到起点 没有duration: 0, 苹果微信小程序轨迹回放图标不能完全回到起点 只会回到一半 没有完全回到起点
最新发布
07-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值