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];}-(VO ID) collisionbehavior :( uicollisionbehavior *) behavior begancontactforitem :( id <uidynamicitem>) item identifier :( id <nscopying>) 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];
<Graphic images, animations, multimedia> Reading Notes-Mechanical Behavior Characteristics