(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];