ios - UIKit Dynamics doesn't allow me to animate a UIView's centre -


i have uiview attached uicollisionbehavior. i'm trying animate center when new location tapped on screen, appears using block of code not way it:

    [uiview animatewithduration:0.7f                           delay:0.0f                         options:uiviewanimationoptioncurveeaseout | uiviewanimationoptionbeginfromcurrentstate                      animations:^{                          [self.maincharacter setcenter:location];                      }                      completion:nil]; 

can suggest more uikitdynamics friendly way of doing this?

thanks.

update

so first part of question similar 1 posted , possible duplicate, however, although technically solved issue in first part of question, seem interfere how collision testing in uicollisionbehavior.

the second part of question ask if there better way of doing this. assumed possible accelerate uidynamicitem @ speed on given time using uipushbehavior seems constant.

can recommend how use uipushbehavior above?

in uikit dynamics, when want animate changing center, you'd add uisnapbehavior uidynamicanimator (removing prior snap behavior first). example, create property uisnapbehavior, , tap gesture recognizer can snap point (honoring uicollisionbehavior), so:

- (void)handletap:(uitapgesturerecognizer *)gesture {     if (self.snap)         [self.animator removebehavior:self.snap];      cgpoint point = [gesture locationinview:gesture.view];     uisnapbehavior *snap = [[uisnapbehavior alloc] initwithitem:self.viewtoanimate snaptopoint:point];     [self.animator addbehavior:snap];      self.snap = snap; } 

you can control "bounciness" adjusting damping property of uisnapbehavior. if don't rotating view it's snapping, can add uidynamicitembehavior allowsrotation set no.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -