pushes UIInterpolatingMotionEffect compliance? (i.e. access to "physics" in UIInterpolatingMotionEffect)

With UIInterpolatingMotionEffect, twist the iPhone and you can move the image.

Now: Imagine a red block that you "bounce" on the screen using UICollisionBehavior and UIDynamicItemBehavior. When the user rotates the iPhone: I want the boxes to “start moving” with the FREE PHYSIC SENSITIVE to use UIInterpolatingMotionEffect.

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

In addition: UX explanation: the bonus effect (example: SMS on iPhone) has the same “feel” as the parallax image effect in iOS. (“Feel,” I just mean the same speed, acceleration.) This will be the third effect: for example, parallax “moved a little”, but they “continued to move”, bouncing a little. (You could say, somewhat combining the feeling of elastic lists-effect and the effect of parallax-images.)

Now: it's relatively easy to do what I am describing using CMAccelerometerData and apply keystrokes using UIPushBehaviorModeInstantaneous. But this is a lot of dirty code.

In contrast, UIInterpolatingMotionEffect is ridiculously easy to use.

Essentially, how can I get the values ​​from UIInterpolatingMotionEffect (which I will then use as push). Hooray!


A similar thought ...

Just display the values ​​of UIInterpolatingMotionEffect? A.

He just asks: how can you easily “just get” the values ​​from UIInterpolatingMotionEffect? those. seems incredible, efforts need to be made to thoroughly subclass CALayer, etc.

+2
source share
1 answer

This is an interesting concept about updating any behavior through UIInterpolatingMotionEffect, although I do not suspect that it is intended for this. If you want to update the behavior based on accelerometer information, I would personally think that is CMMotionManagerideal for this purpose.

UX , , , , . , CMMotionManager 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 . , , .

, , UX.

+3

All Articles