是否可以通过绑定使文本视图和滑块与CGRect的float值保持同步? [英] Is there way to keep a text view and a slider in sync to a CGRect's float value with bindings?

查看:54
本文介绍了是否可以通过绑定使文本视图和滑块与CGRect的float值保持同步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图获得一个文本视图和一个滑块,当其中任何一个被修改时,它们都将更新为正确的值。

I've been trying to get a text view and a slider to be updated to the correct value when either one has been modified.

我使用绑定成功地将每个控件链接到CALayer的 x值位置(layer.position.x)。更改任何控件时,图层均会移动。但是,当修改其中一个控件时,我无法让另一个控件更新自身以反映新更改的值。

Using bindings, I've successfully linked each control to a CALayer's "x" value position (layer.position.x). The layer does move when any of the controls are changed. However, when modifying one of the controls, I cannot get the other control to update itself to reflect the newly changed value.

我尝试实现符合KVC标准的自己的setter和getter方法,但没有调用我的getter方法。我在想,因为这是我直接修改的原始值,所以不存在该值的KVO。有绑定的方法吗?

I tried to implement my own setter and getter methods that align with the KVC standards, but the getter method I have is not getting called. I'm thinking because it's a primitive value that I'm modifying directly, the KVO for that value is not there. Is there a way to do this with bindings?

谢谢

Charles

推荐答案

文本视图,文本字段和CALayers都在 MVC 模式。通过将所有这些视图绑定到控制器的属性,您将获得更好的结果。

Text views, text fields, and CALayers are all in the view layer of the MVC pattern. You'll have much better results by binding all of those views to a property of your controller.

如果我不得不猜测绑定到图层的特定原因,工作时,我将指向 Core Animation的扩展到KVC ,并猜想自动KVO魔术无法使用。

If I had to guess a specific reason why binding to the layer doesn't work, I'd point to Core Animation's extensions to KVC, and guess that the automatic KVO magic doesn't work with it.

我不认为CALayers公开任何绑定,所以您只是需要使控制器的设置器将更改显式传播到CALayer。

I don't think CALayers expose any bindings, so you're just going to have to make the controller's setter explicitly propagate the change to the CALayer.

这篇关于是否可以通过绑定使文本视图和滑块与CGRect的float值保持同步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆