只需显示UIInterpolatingMotionEffect的值? [英] Simply display the values of UIInterpolatingMotionEffect?
问题描述
这是一个难题,想象一个典型的UIInterpolatingMotionEffect,
Here's a puzzle, imagine a typical UIInterpolatingMotionEffect ,,,
UIInterpolatingMotionEffect *horizontalMotionEffect =
[[UIInterpolatingMotionEffect alloc]
initWithKeyPath:@" .. some property .."
type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
horizontalMotionEffect.minimumRelativeValue = @(-50);
horizontalMotionEffect.maximumRelativeValue = @(50);
[someView addMotionEffect:horizontalMotionEffect];
通常,您必须在此处的第3行中放置一个属性,例如center.x
Normally, you have to put in a property in line 3 there -- say, the center.x
但是-如果我(非常简单地)想要查看UIInterpolatingMotionEffect的值怎么办?
But - what if I (very simply) want to see the value of the UIInterpolatingMotionEffect?
(或者,我可能会将其用于其他目的.)
(Or I might use it for some other purpose, say.)
我实际上是否必须继承CALayer并创建新的可动画设置的属性?!
Do I actually have to subclass CALayer and make a new animatable property?!
仅访问值似乎非常复杂.我能想到的唯一技巧就是制作一个不可见的视图,将其设置为中心,然后访问该值!虽然看起来很傻.
It seems incredibly complicated to just access the value. The only trick I could think of was just make an invisible view, set it to the center, and access the value! Seems silly though.
有什么想法吗?
推荐答案
您可以将UIInterpolatingMotionEffect
子类化,并挂接到方法-(NSDictionary *)keyPathsAndRelativeValuesForViewerOffset:(UIOffset)viewerOffset
中,以记录viewerOffset
以获得规范化的值,或者查看字典中的super实现返回以获取您的最小值和最大值之间的插值.
You can subclass UIInterpolatingMotionEffect
and hook into the method -(NSDictionary *)keyPathsAndRelativeValuesForViewerOffset:(UIOffset)viewerOffset
to log either viewerOffset
to get the normalized values or look into the dictionary that the super implementation returns to get the interpolated values between your min and max.
UILogInterpolatingMotionEffect.h
UILogInterpolatingMotionEffect.h
@interface UILogInterpolatingMotionEffect : UIInterpolatingMotionEffect
@end
UILogInterpolatingMotionEffect.m
UILogInterpolatingMotionEffect.m
@implementation UILogInterpolatingMotionEffect
-(NSDictionary *)keyPathsAndRelativeValuesForViewerOffset:(UIOffset)viewerOffset
{
NSDictionary *superDictionary = [super keyPathsAndRelativeValuesForViewerOffset:viewerOffset)];
NSLog(@"%@, %@", NSStringFromUIOffset(viewerOffset), superDictionary);
return superDictionary;
}
@end
PS:如果您只对viewerOffset感兴趣,则可以甚至将UIMotionEffect
子类化.另请参见 UIMotionEffect类引用.
PS: If you are only interested in the viewerOffset, you can even subclass UIMotionEffect
. See also the UIMotionEffect class reference.
这篇关于只需显示UIInterpolatingMotionEffect的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!