(Graphic Images, animations, multimedia) Reading Notes-Mechanical Behavior Characteristics

Source: Internet
Author: User

(Graphic Images, animations, multimedia) Reading Notes-Mechanical Behavior Characteristics

UIKit mechanical behaviors include: UIGravityBehavior, UICollisionBehavior, UIAttachmentBehavior, uipus?havior, UISnapBehavior, and behavior restriction ).


-(Void) viewDidAppear :( BOOL) animated {[super viewDidAppear: animated]; _ animator = [[UIDynamicAnimator alloc] initWithReferenceView: self. view]; // gravity behavior _ gravity = [[UIGravityBehavior alloc] initWithItems: @ [_ box]; [_ animator addBehavior: _ gravity]; // collision behavior _ collision = [[UICollisionBehavior alloc] initWithItems: @ [_ box]; [_ collision addBoundaryWithIdentifier: @ "barrier" fromPoint: _ barrier. frame. origin toPoint: CGPointMake (_ barrier. frame. origin. x + _ barrier. frame. size. width, _ barrier. frame. origin. y)]; _ collision. translatesreferencebounds=boundary = YES; _ collision. collisionDelegate = self; [_ animator addBehavior: _ collision]; UIDynamicItemBehavior * itemBehaviour = [[delealloc] initWithItems: @ [_ box]; itemBehaviour. elasticity = 0.5; [_ animator addBehavior: itemBehaviour];}-(void) collisionBehavior :( UICollisionBehavior *) behavior beganContactForItem :( id
 
  
) Item withBoundaryIdentifier :( id
  
   
) Identifier atPoint :( CGPoint) p {if (! _ FirstContact) {_ firstContact = YES; // sets the adsorption behavior self. attach = [[UIAttachmentBehavior alloc] initWithItem: _ attachmentPoint attachedToItem: _ box]; [self. animator addBehavior: self. attach]; // set the push behavior uipus?havior * push = [[uipus?havior alloc] initWithItems: @ [_ box] mode: uipus?haviormodeinstantaneous]; // [push setAngle: -M_PI/4 magnction: 5.0f]; // 45 degrees CGVector pushDirection = {0.5,-0.5} in the upper right corner; // setAngle: magnction: Alternative method [push setPushDirection: pushDirection]; [push setmagncategory: 5.0f]; [_ animator addBehavior: push];}
  
 


I personally think it is more useful, that is, behavior rejection.

-(Void) viewDidAppear :( BOOL) animated {[super viewDidAppear: animated]; _ animator = [[UIDynamicAnimator alloc] initWithReferenceView: self. view];}-(IBAction) handleSnapGesture :( UITapGestureRecognizer *) gesture {CGPoint point = [gesture locationInView: self. view]; // remove the behavior [_ animator removeBehavior: _ snap]; _ snap = [[UISnapBehavior alloc] initWithItem: _ box snapToPoint: point]; [self. animator addBehavior: _ snap];}

Another method is similar to changing the view displacement of the desktop with the wrist angle.

// Set the offset range of the mountain on the X axis-50.0 ~ 50.0 UIInterpolatingMotionEffect * mountainEffectX; mountainEffectX = [[UIInterpolatingMotionEffect alloc] initWithKeyPath: @ "center. x "type: UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis]; mountainEffectX. maximumRelativeValue = @ 50.0; mountainEffectX. minimumRelativeValue = @-50.0; [self. mountain addMotionEffect: mountainEffectX]; // set the offset range of the tree on the X axis to-100.0 ~ 100.0 UIInterpolatingMotionEffect * treeEffectX; treeEffectX = [[UIInterpolatingMotionEffect alloc] initWithKeyPath: @ "center. x "type: UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis]; treeEffectX. maximumRelativeValue = @ 100.0; treeEffectX. minimumRelativeValue = @-100.0; [self. tree addMotionEffect: treeEffectX];

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.