IOS Mechanics Animation Generator Uikit Dynamics Collision effect Explained

Source: Internet
Author: User

UIKit Dynamic is a new set of classes and methods iOS7 that give uiview realistic behavior and features without the tedious code of writing animations, making it easy for developers to improve the user experience of the app. A total of 6 classes can be used to customize Uidynamicanimator, here is a simple introduction to the impact of the animation effect, that is, Uicollisionbehavior. Need to sign an agency agreement:uicollisionbehaviordelegate. Other effects, follow up updates, please look forward to.


#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]];


< Span style= "FONT-SIZE:13PX; Color:rgb (76,191,87); Font-family:menlo ">    //&NBSP; uicollisionbehaviormodeitems ( Span style= "Color:rgb (76,191,87); font-family: ' Heiti SC Light ' "objects collide with each other )   

< Span style= "font-size:12px" >                          uicollisionbehaviormodeboundaries

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 when the collision starts ");

}


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

{

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

}


@end


IOS Mechanics Animation Generator Uikit Dynamics Collision effect Explained

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.