这是一个谜题,想象一个典型的 UIInterpolatingMotionEffect ,
UIInterpolatingMotionEffect *horizontalMotionEffect =
[[UIInterpolatingMotionEffect alloc]
initWithKeyPath:@" .. some property .."
type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
horizontalMotionEffect.minimumRelativeValue = @(-50);
horizontalMotionEffect.maximumRelativeValue = @(50);
[someView addMotionEffect:horizontalMotionEffect];
通常,您必须在第 3 行中放入一个属性 - 比如说 center.x
但是 - 如果我(非常简单)想查看 UIInterpolatingMotionEffect 的值怎么办?
(或者我可能会将它用于其他目的。)
我真的必须继承 CALayer 并创建一个新的可动画属性吗?!
仅仅访问该值似乎非常复杂。我能想到的唯一技巧就是制作一个不可见的视图,将其设置为中心,然后访问值!虽然看起来很傻。
有任何想法吗?
你可以子类化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 类参考 https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIMotionEffect_class/index.html#//apple_ref/occ/instm/UIMotionEffect/keyPathsAndRelativeValuesForViewerOffset.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)