IOS7 Uikit Dynamics-Collision characteristics Uicollisionbehavior

Source: Internet
Author: User
Tags uikit

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

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.