首页 \ 问答 \ UISwitch不返回其当前状态(开/关)(UISwitch not returning its current state (on/off))

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
更新时间:2023-11-28 19:11

最满意答案

将回调传递给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.

相关问答

更多
  • 就像用户@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 ...
  • 例如,您可以使用“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 ` I guess you can use TouchableX inside the Animated.View s ...
  • 将回调传递给启动函数以检查是否重新启动动画。 你可以把它分解成这样的东西: onSpringCompletion = () => { if (arbitraryCondition) { this.spring(); } } spring = () => { this.springValue.setValue(0.3) Animated.spring( this.springValue, { toVa ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。