“推”匹配UIInterpolatingMotionEffect? (即访问UIInterpolatingMotionEffect上的“物理”)

使用UIInterpolatingMotionEffect,扭转iPhone,你可以有一个图像移动。

现在想象一下,使用UICollisionBehavior和UIDynamicItemBehavior,你会在屏幕上“反弹”一个红色块。 当用户扭曲iPhone:我想要的箱子“开始移动”与类似的物理感觉使用UIInterpolatingMotionEffect。

http://tinypic.com/player.php?v=b67mlc%3E&s=8#.VBVEq0uZNFx

另外:UX解释:弹性效果(例如:iPhone上的SMS)与iOS中的视差图像效果具有相同的“感觉”。 (通过“感觉”,我的意思是同样的速度,加速度。)这将是第三个效果:像“视差”,它会“轻微移动”,但会“继续移动”,反弹一点。 (你可以说,有点结合了弹性列表效果和视差效果的感觉。)

现在:使用CMAccelerometerData来描述我的描述是相对容易的,并且使用UIPushBehaviorModeInstantaneous来应用推送。 但是这是很多杂乱的代码。

相反,UIInterpolatingMotionEffect是可笑的容易使用。

本质上,我怎么能从UIInterpolatingMotionEffect(我将作为推)使用这些值。 干杯!


类似的想法…

只需显示UIInterpolatingMotionEffect的值?

它简单地问:如何才能轻松地从UIInterpolatingMotionEffect中“获取”值? 即,看起来不可思议的人不得不仔细分类CALayer等等。

通过UIInterpolatingMotionEffect更新一些行为是一个有趣的概念,但我不怀疑它是为此而devise的。 如果你想根据加速度计信息更新行为,我个人会认为CMMotionManager是理想的。

所需的用户体验在video剪辑中并不完全清晰,但是看起来像是video在手机倾斜的方向继续滑动,直到您停止倾斜手机。 如果这就是你想要的,我会倾向于与UIKit Dynamics UIGravityBehavior

 self.animator = [[UIDynamicAnimator alloc] initWithReferenceView:container]; UICollisionBehavior *collision = [[UICollisionBehavior alloc] initWithItems:container.subviews]; collision.translatesReferenceBoundsIntoBoundary = YES; [self.animator addBehavior:collision]; UIGravityBehavior *gravity = [[UIGravityBehavior alloc] initWithItems:container.subviews]; gravity.gravityDirection = CGVectorMake(0, 0); [self.animator addBehavior:gravity]; self.motionManager = [[CMMotionManager alloc] init]; typeof(self) __weak weakSelf = self; [self.motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMDeviceMotion *motion, NSError *error) { if (weakSelf.referenceAttitude == nil) { weakSelf.referenceAttitude = motion.attitude; } else { CMAttitude *attitude = motion.attitude; [attitude multiplyByInverseOfAttitude:weakSelf.referenceAttitude]; gravity.gravityDirection = CGVectorMake(attitude.roll * 5.0, attitude.pitch * 5.0); } }]; 

如果你想让他们按照态度精确地移动,当你停止移动设备时(如UIInterpolatingMotionEffect所做的那样)停止移动,你可以使用UIAttachmentBehavior ,如:

 UIAttachmentBehavior *attachment = [[UIAttachmentBehavior alloc] initWithItem:viewToAttachTo attachedToAnchor:viewToAttachTo.center]; [self.animator addBehavior:attachment]; self.motionManager = [[CMMotionManager alloc] init]; self.motionManager.deviceMotionUpdateInterval = 1.0 / 20.0; typeof(self) __weak weakSelf = self; CGPoint originalAnchorPoint = viewToAttachTo.center; [self.motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMDeviceMotion *motion, NSError *error) { if (weakSelf.referenceAttitude == nil) { weakSelf.referenceAttitude = motion.attitude; } else { CMAttitude *attitude = motion.attitude; [attitude multiplyByInverseOfAttitude:weakSelf.referenceAttitude]; attachment.anchorPoint = CGPointMake(originalAnchorPoint.x + attitude.roll * 10.0, originalAnchorPoint.y + attitude.pitch * 10.0); } }]; 

请注意,在这两个示例中,我将调整应用于设备从用户启动应用程序时的设备方向转换。 因此,我捕获了CMAttitude属性, referenceAttitude是用户启动应用程序时设备的态度,然后在随后的更新中使用multiplyByInverseOfAttitude以应用与原始方向相关的引力。 显然,如果你想要的话,你也可以使用预定的态度。

但希望以上说明了解决这种用户体验的一种方法。