IOS Mechanics Animation Builder Uikit Dynamics Collision effect Commentary

Source: Internet
Author: User

UIKit Dynamic is a new set of classes and methods IOS7. Can give uiview realistic behavior and characteristics, do not need to write animation effect of those cumbersome code, so that developers can easily improve the user experience of the app. A common group of 6 classes that can be used to customize Uidynamicanimator. Here is just a brief introduction to the impact of the animation effect, that is, Uicollisionbehavior. Need to sign an agency agreement:uicollisionbehaviordelegate.

Other effects, perhaps updates, please look forward to.

Note: Dragonimageview and Frogimageview Remember to initialize also: uidynamicanimator, Uigravitybehavior, Uicollisionbehavior must be declared as attributes or global variables, otherwise it will not produce animation effects!


#import "ICFCollisionViewController.h"

@interface Icfcollisionviewcontroller ()

{

Uiimageview *dragonimageview;

uiimageview*frogimageview;

}

@end


@implementation Icfcollisionviewcontroller


-(ID) initwithnibname: (nsstring *) Nibnameornil Bundle: (nsbundle *) Nibbundleornil

{

self = [superinitwithnibname: Nibnameornilbundle: Nibbundleornil];

if (self) {

}

return self;

}


-(void) viewdidload

{

[superviewdidload];

// Initialize Mechanics animation generator

uidynamicanimator *Animator = [[uidynamicanimatoralloc] Initwithreferenceview:self. View];

// Create a gravity drop effect object

uigravitybehavior *gravitybehavior = [[uigravitybehavioralloc]initwithitems : @[frogimageview,Dragonimageview]];


// set acceleration of gravity. Horizontal and vertical Direction

[Gravitybehavior setgravitydirection:cgvectormake(0.0f, 0.3f)];

   //  object that creates a collision effect

uicollisionbehavior* collisionbehavior = [[uicollisionbehavioralloc] Initwithitems: @[frogimageview,Dragonimageview]];


    //  The collision mode of the object has a common three kinds: uicollisionbehaviormodeitems ( objects collide with each other )   

< Span style= "font-size:12px" >                          uicollisionbehaviormodeboundaries (objects do not collide with each other.) Collision with boundary only)                             

uicollisionbehaviormodeeverything (collision with object and boundary)

[Collisionbehavior setcollisionmode:uicollisionbehaviormodeeverything];

the function of this code is to use the Self.view border as the collision boundary and must be set to Yes, otherwise no collision effect will be generated

Collisionbehavior. Translatesreferenceboundsintoboundary =YES;

[animatoraddbehavior: Gravitybehavior];

[animatoraddbehavior: Collisionbehavior];

Collisionbehavior. collisiondelegate =self;

}


-(void) Collisionbehavior: (uicollisionbehavior *) behavior Begancontactforitem: (ID< Uidynamicitem>) Item Withboundaryidentifier: (ID<nscopying>) identifier Atpoint :(cgpoint) p

{

NSLog(@ "The method triggered at the start of the collision");

}


-(void) Collisionbehavior: (uicollisionbehavior *) behavior Endedcontactforitem: (ID< Uidynamicitem>) Item Withboundaryidentifier: (ID<nscopying>) identifier

{

NSLog(@ " method to trigger at end of collision ");

}


@end


IOS Mechanics Animation Builder Uikit Dynamics Collision effect Commentary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.