UISwitch不返回其当前状态(开/关)(UISwitch not returning its current state (on/off))
下面是通过valueChanged事件链接到UISwitch的IBAction方法:
- (IBAction) sanitySwitch { if (checkoption.on == YES) { NSLog(@"SanityCheck ENABLED"); sanityCheck = YES; } else { NSLog(@"SanityCheck DISABLED"); sanityCheck = NO; } }
它总是返回“SanityCheck DISABLED”。 UISwitch checkoption正确地连接到XIB文件中的对象,并且已经放置了正确的@propery和@syntetize设置。
Here is the IBAction method linked to the UISwitch with the valueChanged event :
- (IBAction) sanitySwitch { if (checkoption.on == YES) { NSLog(@"SanityCheck ENABLED"); sanityCheck = YES; } else { NSLog(@"SanityCheck DISABLED"); sanityCheck = NO; } }
It always returns "SanityCheck DISABLED". The UISwitch checkoption is correcty linked to its object from the XIB file and proper @propery and @syntetize setting have been placed.
原文:https://stackoverflow.com/questions/3715531
最满意答案
将回调传递给
Animated.start()
,重置动画值并再次启动动画。 例如:componentDidMount(){ this.runAnimation(); } runAnimation() { this.animatedValue.setValue(300); Animated.timing(this.animatedValue, { toValue: -100, duration: 3000, }).start(() => this.runAnimation()); }
如果您需要在任何时候停止动画,请查看此问题/答案 。
Pass a callback to
Animated.start()
that resets the Animated value and starts the animation again. For example:componentDidMount(){ this.runAnimation(); } runAnimation() { this.animatedValue.setValue(300); Animated.timing(this.animatedValue, { toValue: -100, duration: 3000, }).start(() => this.runAnimation()); }
If you need to stop the animation at any point, take a look at this question/answer.
相关问答
更多-
回应原生动画 - 在缩放时使用translateX和translateY(React Native animations - translateX and translateY while scaling)[2021-12-04]
就像用户@ArneHugo在评论中指出的那样,非线性运动可以通过定位全尺寸容器元素并缩放其中的另一个元素来解决。 元素的位置与预期不符,因为缩放变换的原点是元素的中心点。 React Native不支持指定转换原点,但如果预先知道缩放元素的宽度和高度,则可以很容易地计算偏移量,如下所示: const width = 100; const height = 20; const scale = { transform: [ { scale: this.animatedValue.inte ... -
好吧,我想出了如何做到这一点。 像这样创建一个单独的文件: import React, { Component } from 'react'; import { Animated, } from 'react-native'; var Anims = { firstAnim(move) { Animated.sequence([ Animated.timing(move,{ toValue: {x: 50, y: 100}, duration:400 }), Animate ...
-
将回调传递给Animated.start() ,重置动画值并再次启动动画。 例如: componentDidMount(){ this.runAnimation(); } runAnimation() { this.animatedValue.setValue(300); Animated.timing(this.animatedValue, { toValue: -100, duration: 3000, }).start(() => this.runAnimation( ...
-
我认为这是你想要的: 动画实际上非常流畅,在GIF中看起来并不如此,因为GIF是4帧每秒。 这里是代码(因为你的数字都是常量,所以我只是在下面的代码中硬编码): import React, { Component } from 'react' import { Animated, View, TouchableOpacity, Easing } from 'react-native' const backgroundImage = require('....') class App extends Co ...
-
反应原生动画(Animation in react-native)[2022-09-18]
例如,您可以使用“scale”缩小componentDidMount上的图像大小。 如果我理解正确,这就是你想要的 class Playground extends React.Component { state = { scaleValue: new Animated.Value(1), } componentDidMount() { Animated.spring( this.state.scaleValue, ... -
你需要放松。 import { Animated, Easing } from 'react-native'; ... Animated.timing(this.state.scale, { toValue: 1.3, duration: 2000, easing: Easing.linear }) You need Easing. import { Animated, Easing } from 'react-native'; ... Animated.timing( ...
-
要同时制作多个动画,只需创建多个Animated.Value ,或多次interpolate 。 移动轨迹是关于使用三角函数计算translateX和translateY 。 translateX对应于Math.sin() ,而translateY对应于Math.cos() 。 选项二的代码(多次从一个Animated.Value插值): export class App extends Component { constructor() { super() this ...
-
您可以使用商店来保持动画值。 但IMO这是个坏主意。 只需使用课程。 你应该更灵活;) 作为替代方案,您可以使用声明性语法尝试https://github.com/oblador/react-native-animatable 。 我之前没有使用它,但看起来它可以帮助。 You can use store to keep animated values of course. But IMO it is bad idea. Just use classes. You should be more flexib ...
-
我想你可以在Animated.View中使用TouchableX
stuff s ... -
将回调传递给启动函数以检查是否重新启动动画。 你可以把它分解成这样的东西: onSpringCompletion = () => { if (arbitraryCondition) { this.spring(); } } spring = () => { this.springValue.setValue(0.3) Animated.spring( this.springValue, { toVa ...