反応ネイティブ回転の主な問題は、ほとんどのデバイスで十分にサポートされていないことです。 これは、お使いのデバイスで正しく動作しないか、まったく利用できない可能性があることを意味します.
animation import React, { Component } from 'react'; import { Animated, Text, View } from 'react-native'; class FadeInView extends Component { state = { fadeAnim: new Animated.Value(0), // Initial value for opacity: 0 } componentDidMount() { Animated.timing( // Animate over time this.state.fadeAnim, // The animated value to drive { toValue: 1, // Animate to opacity: 1 (opaque) duration: 10000, // Make it take a while }, ).start(); // Starts the animation } render() { let { fadeAnim } = this.state; return ( <Animated.View // Special animatable View style={{ ...this.props.style, opacity: fadeAnim, transform:[{rotate:'360deg'}] }} > {this.props.children} </Animated.View> ); } }
このコード行ごと:
import React, { Component } from 'react'; import { Animated, Text, View } from 'react-native'; class FadeInView extends Component { state = { fadeAnim: new Animated.Value(0), // 不透明度の初期値: 0 } componentDidMount() { Animated.timing( // 時間をかけてアニメーション化する this.state.fadeAnim, // アニメーション化された駆動する値 { toValue: 1, // opacity: 1 (不透明) にアニメーション化します duration: 10000, // しばらく時間がかかります }, ).start(); // アニメーションを開始します } render() { let { fadeAnim } = this.state; 戻る (
変換
React Native で実行できる変換にはいくつかの種類があります。 これらには以下が含まれます:
レイアウト変換: アプリのレイアウトを変更します。 たとえば、アプリ ウィンドウの高さや幅を変更できます。
アニメーション変換: これらは、要素が時間の経過とともにどのように動くように見えるかを変更します。 たとえば、要素の不透明度を変更したり、別の形状に変形したりできます。
状態管理の変換: これらは、読み込み中やユーザーによる操作中など、さまざまな状態にあるときのアプリの動作を変更します。
アニメーションを使用して画像を回転する
React Native では、アニメーション コンポーネントを使用して画像を回転できます。
まず、アニメーション コンポーネントをインポートする必要があります。
import { Animation } from 'react-native'
次に、新しい Animation インスタンスを作成する必要があります。
let アニメーション = new アニメーション()
animation.fromRect(0, 0, 100, 100) // アニメーションの開始点を設定します。 animation.toRect(50, 50, 150, 150) // アニメーションの終了点を設定します。 animation.duration = 1000 // アニメーションの持続時間をミリ秒単位で設定します。