We talked about the gravity of the above property Uigravitybehavior this class.
Very clear view, when we add the severity of the attribute, the Apple uiview like falling into the bottomless pit, falling underground, constantly accelerating. And now, we're going to add a ground on this phone screen. Finally, the falling Apple has a landing point. So how do we add a ground to this view? For example the following (the current content to undertake the above content, if there is a problem.) Please see above: uigravitybehavior):
First create a Uicollisionbehavior object in the. h file
. h:
#import <UIKit/UIKit.h> @interface viewcontroller:uiviewcontroller{ uidynamicanimator * _animator; Uigravitybehavior * _gravity; New Uicollisionbehavior * _ground;} @end
The Uicollisionbehavior object is then initialized in the. m file . and set border properties for Apple objects.
-(void) viewdidload{ [Super Viewdidload]; UIView * Apple = [[UIView alloc] Initwithframe:cgrectmake (40,40, +, +)]; Apple.backgroundcolor = [Uicolor redcolor]; [Self.view addsubview:apple]; _animator = [[Uidynamicanimator alloc] initWithReferenceView:self.view]; _gravity = [[Uigravitybehavior alloc] initwithitems:@[apple]; [_animator addbehavior:_gravity]; /* uicollisionbehavior */ _ground = [[Uicollisionbehavior alloc] initwithitems:@[apple]]; _ground.translatesreferenceboundsintoboundary = YES; [_animator Addbehavior:_ground];}
Here, the code above creates a collision behavior. It defines the nature of one or more boundary interactions, which is not shown to add boundaries to each space, but implicitly invokes a Uicollisionbehavior attribute translatesreferenceboundsintoboundary, After you set this property to Yes.
Causes the boundary reference to use the Uidynamicanimator boundary provided by the view. Build and execute, and you'll see the effect, and Apple falls to the ground and bounces back to the ground again.
Click Follow me 。 Many other wonderful content!!!
Group number: 336146073
copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
IOS7 uikit Dynamics-collision characteristics Uicollisionbehavior on