cs193p – Assignment #4 Extra Task #4

Please note, this blog entry is from a previous course. You might want to check out the current one.

Think of some other way(s) to use animation in your application and implement it.

What happens if you shake your iPhone? The card go crazy:

- (BOOL)canBecomeFirstResponder
{
    return YES;
}

- (void)viewDidAppear:(BOOL)animated
{
    [self becomeFirstResponder];
}

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    if (motion == UIEventSubtypeMotionShake) {
        if (!self.pileAnimator) {
            self.pileAnimator = [[UIDynamicAnimator alloc] initWithReferenceView:self.gridView];
            UIGravityBehavior *gravity = [[UIGravityBehavior alloc] initWithItems:self.cardViews];
            [self.pileAnimator addBehavior:gravity];
            UICollisionBehavior *collision = [[UICollisionBehavior alloc] initWithItems:self.cardViews];
            collision.translatesReferenceBoundsIntoBoundary = YES;
            [self.pileAnimator addBehavior:collision];
            UIDynamicItemBehavior *item = [[UIDynamicItemBehavior alloc] initWithItems:self.cardViews];
            item.elasticity = 1.1;
            [self.pileAnimator addBehavior:item];
        } else {
            self.pileAnimator = nil;
            [self updateUI];
        }
    }
}

… if you shake again, the return to their assigned places, but the might still be crazy (just throw them away and deal a new deck):

cs193p – assignment #4 extra task #4 – crazy cards
cs193p – assignment #4 extra task #4 – crazy cards

The complete code is available on github.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

3 thoughts on “cs193p – Assignment #4 Extra Task #4”

  1. Is there a way that I can access to the description of the HWs themselves? rather than the code?

    1. Could you please be more specific?

      You can find the complete homework assignments on iTunes together with lectures and slides. You can find a copy of the individual tasks at the beginning of each respective blog entry here. A description of what the code is intended to do is interspersed between the code snippets in the blog entries as well …

Leave a Reply

Your email address will not be published.