【问题标题】:Simply display the values of UIInterpolatingMotionEffect?只显示 UIInterpolatingMotionEffect 的值?
【发布时间】:2014-09-12 14:25:07
【问题描述】:

这是一个谜题,想象一个典型的 UIInterpolatingMotionEffect ,,,

UIInterpolatingMotionEffect *horizontalMotionEffect =
  [[UIInterpolatingMotionEffect alloc]
    initWithKeyPath:@" .. some property .."
     type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
horizontalMotionEffect.minimumRelativeValue = @(-50);
horizontalMotionEffect.maximumRelativeValue = @(50);
[someView addMotionEffect:horizontalMotionEffect];

通常,您必须在第 3 行中放入一个属性,例如 center.x

但是 - 如果我(非常简单地)想查看 UIInterpolatingMotionEffect 的值怎么办?

(或者我可能会将其用于其他目的。)

我真的必须继承 CALayer 并创建一个新的动画属性吗?!

仅访问该值似乎非常复杂。我能想到的唯一技巧就是制作一个不可见的视图,将其设置为中心,然后访问该值!不过看起来很傻。

有什么想法吗?

【问题讨论】:

  • 嗯,我不知道。假设有一个属性(已经内置)UIView,它只是给出了当前附加的 UIInterpolatingMotionEffect 的“值”。然后工作就完成了,就这么简单。根据定义,您将使用与苹果在 UIInterpolatingMotionEffect 中使用的“相同”物理。 (加上 CMMotionManager 仍然很麻烦——打开和关闭它等等,改变它指向的地方,等等。)再次抛开我的另一个问题,似乎不可思议的是,不能简单地从 UIInterpolatingMotionEffect 中“获取”值! (只是为了登录,为了兴趣!)干杯!
  • 我明白你在说什么,但你不是必须设置一些东西(CADisplayLinkNSTimer)来不断轮询这个“值”并正确更新行为。我猜你可能有一个action 处理程序来处理询问该“值”状态的行为,但话又说回来,我不知道你如何从UIInterpolatingMotionEffect 获得该值...
  • 等一下 - 假设你添加了一个属性,浮动,“.updatedByMotionEffect”,它是可动画的,并且你让 UIInterpolatingMotionEffect 更新它,就像你可以更新 UIInterpolatingMotionEffect 一样,比如“.center.x”。事实上...... UIInterpolatingMotionEffect 确实不关心 CADisplayLink 方面吗? (这就是我一直假设的。)所以,您所要做的就是 KVO 属性“.updatedByMotionEffect”,并且(再次 - 这就是我认为是 updatedByMotionEffect 的全部意义)然后它会神奇地更新 prpoerties 在它的照顾下,随着时间的推移以正确的方式......
  • @JoeBlow 你解决问题了吗?我确实需要观察自定义属性的变化...
  • 我相信没有办法“监控” UI Interp。影响!可以想象,这可能会有所帮助.. stackoverflow.com/questions/10387406/…

标签: ios uiview calayer key-value-observing uimotion


【解决方案1】:

您可以继承 UIInterpolatingMotionEffect 并挂钩到方法 -(NSDictionary *)keyPathsAndRelativeValuesForViewerOffset:(UIOffset)viewerOffset 以记录 viewerOffset 以获取标准化值,或者查看超级实现返回的字典以获取最小值和最大值之间的插值。

UILogInterpolatingMotionEffect.h

@interface UILogInterpolatingMotionEffect : UIInterpolatingMotionEffect

@end

UILogInterpolatingMotionEffect.m

@implementation UILogInterpolatingMotionEffect

-(NSDictionary *)keyPathsAndRelativeValuesForViewerOffset:(UIOffset)viewerOffset
{
    NSDictionary *superDictionary = [super keyPathsAndRelativeValuesForViewerOffset:viewerOffset)];
    NSLog(@"%@, %@", NSStringFromUIOffset(viewerOffset), superDictionary);
    return superDictionary;
}

@end

PS:如果你只对viewerOffset感兴趣,你甚至可以继承UIMotionEffect。另请参阅UIMotionEffect class reference

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-09-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多