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