React Native SVG Animated 绘制动画
2018-01-09 17:49
1006 查看
转自:React Native SVG描边动画 stroke属性 stroke 定义描边颜色 [code]stroke="#0078ff"strokeWidth 定义描边的宽度
strokeWidth="3"创建虚线时候用到的属性:
strokeDasharray 创建虚线
// 假设一个‘空格’5像素,一个‘_’5像素 strokeDasharray="5" // 看到的是 _ _ _ _ 即5像素实线,5像素空白,5像素实线,.... 循环 strokeDasharray="5,10" // 看到的是 _ _ _ _ 5像素实线,10像素空白...循环strokeDashoffset 虚线的位移
strokeDasharray="5" strokeDashoffset="1" // 看到的第一个_会往左边挪动1像素描边动画
有足够长的空白,控制位移,让空白的位置移动,实线的位置就会慢慢显示出来。
假设灰色区域宽度300:
Untitled 3.png
如果strokeDashoffset从300到0连续变化,就是描边了
有一小段实线在奔跑
有足够长的空白,有一小段实线,改变strokeDashoffset控制空白的移动
Untitled 2.png如果strokeDashoffset从20到320连续变化,会看到小段实线从右向左滑动过来。画曲线就可以跑曲线了。
跑个栗子在react-native里,可以用animated改变strokeDashoffset的值来做动画。
另:类似sketch等软件可以绘矢量图并存成svg格式,基本上改改就能用了比较方便。
rn
npm install --save react-native-svg使用react-native里的ART的话,strokeDasharray和strokeDashoffset写在strokeDash属性里。
一个不是例子的栗子:
import {
Animated
...
} from 'react-native';
import Svg, {
G,
Path
} from 'react-native-svg';
// 注意要用 Animated.createAnimatedComponent 让组件可动画化
let AnimatePath = Animated.createAnimatedComponent(Path);
...
constructor (props) {
super(props);
this.state = {
strokeDashOffset: new Animated.Value(38)
}
}
changeStroke = () => {
// 使用炫酷的animated让小线段愉悦的奔跑�
Animated.spring(
this.state.strokeDashOffset,
{
toValue: 243
}
).start();
};
render () {
return (
<View>
...
<TouchableWithoutFeedback
onPress={this.changeStroke}
>
<Svg
height="100"
width="100"
>
<G fill="none">
<AnimatePath
d={一坨路径}
stroke="#0078FF"
strokeWidth="3"strokeDasharray="28,215"
strokeDashoffset={this.state.strokeDashOffset}
/>
</G>
</Svg>
</TouchableWithoutFeedback>
</View>
)
}
相关文章推荐
- reactnative Animated 插值动画(interpolate)
- React Native Animated 动画之 加载中loading
- react-native使用react-art制作SVG动画
- react native 之动画
- React-Native项目中使用动画-Animated
- https://isux.tencent.com/svg-animate.html(svg动画)
- react-native动画的坑
- React Native开发之动画(Animations)
- React Native动画的锚点anchorPoint
- react-native 仿京东加入购物车动画效果
- React Native超棒的LayoutAnimation(布局动画)
- React Native LayoutAnimation动画
- React Native 下拉刷新添加自定义动画
- 从零开始 React Native (5) React 数据传递_表单_函数复用_动画
- react-native与svg整合 ----- react-native-svg
- ReactNative——动画学习
- SVG 动画(animate、animateTransform、animateMotion)
- React Native开源特效动画封装库模块(lottie-react-native)
- 程序猿必备的10款超有趣的SVG绘制动画赏析
- [HTML5-SVG]使用raphaeljs:绘制哆啦A梦并实现动画效果