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